Skip to content

Commit efada58

Browse files
committed
Update validation and DTO for employeeNumber field in inetOrgPerson
1 parent 6b0ecd8 commit efada58

File tree

7 files changed

+58
-11
lines changed

7 files changed

+58
-11
lines changed

src/_common/pipes/dto-validation.pipe.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class DtoValidationPipe extends ValidationPipe {
4343
return error;
4444
});
4545
}
46+
console.log('validations', JSON.stringify(request.body));
4647
return new BadRequestException({
4748
statusCode: HttpStatus.BAD_REQUEST,
4849
message,

src/core/backends/backends.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class BackendsService extends AbstractQueueProcessor {
4343
{ new: true },
4444
);
4545
if (isSyncedJob) {
46-
await this.identitiesService.model.findByIdAndUpdate(isSyncedJob.concernedTo, {
46+
await this.identitiesService.model.findByIdAndUpdate(isSyncedJob.concernedTo.id, {
4747
$set: {
4848
state: IdentityState.SYNCED,
4949
},
@@ -80,7 +80,7 @@ export class BackendsService extends AbstractQueueProcessor {
8080
},
8181
{ new: true },
8282
);
83-
await this.identitiesService.model.findByIdAndUpdate(failedJob.concernedTo, {
83+
await this.identitiesService.model.findByIdAndUpdate(failedJob.concernedTo.id, {
8484
$set: {
8585
state: IdentityState.ON_ERROR,
8686
},
@@ -99,7 +99,7 @@ export class BackendsService extends AbstractQueueProcessor {
9999
},
100100
{ upsert: true, new: true },
101101
);
102-
await this.identitiesService.model.findByIdAndUpdate(completedJob.concernedTo, {
102+
await this.identitiesService.model.findByIdAndUpdate(completedJob.concernedTo.id, {
103103
$set: {
104104
state: IdentityState.SYNCED,
105105
},
@@ -202,11 +202,16 @@ export class BackendsService extends AbstractQueueProcessor {
202202
optionals['processedAt'] = new Date();
203203
optionals['state'] = JobState.IN_PROGRESS;
204204
}
205+
const identity = await this.identitiesService.findById<Identities>(concernedTo);
205206
const jobStore = await this.jobsService.create<Jobs>({
206207
jobId: job.id,
207208
action: actionType,
208209
params: payload,
209-
concernedTo: concernedTo,
210+
concernedTo: {
211+
$ref: 'identities',
212+
id: concernedTo,
213+
name: [identity.inetOrgPerson?.cn, identity.inetOrgPerson?.givenName].join(' '),
214+
},
210215
comment: options?.comment,
211216
task: options?.task,
212217
state: JobState.CREATED,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsMongoId, IsNotEmpty, IsOptional, IsString } from 'class-validator';
3+
import { Types } from 'mongoose';
4+
5+
export class ConcernedToPartDTO {
6+
@IsString()
7+
@IsNotEmpty()
8+
@ApiProperty()
9+
public $ref: string;
10+
11+
@IsMongoId()
12+
@ApiProperty()
13+
public id: Types.ObjectId;
14+
15+
@IsString()
16+
@IsOptional()
17+
@ApiProperty()
18+
public name?: string;
19+
}

src/core/jobs/_dto/jobs.dto.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ApiProperty, PartialType } from '@nestjs/swagger';
2-
import { IsMongoId, IsObject, IsString } from 'class-validator';
2+
import { Type } from 'class-transformer';
3+
import { IsMongoId, IsNotEmpty, IsObject, IsString, ValidateNested } from 'class-validator';
34
import { Types } from 'mongoose';
45
import { CustomFieldsDto } from '~/_common/abstracts/dto/custom-fields.dto';
6+
import { ConcernedToPartDTO } from './_parts/concerned-to.part.dto';
57

68
export class JobsCreateDto extends CustomFieldsDto {
79
@IsString()
@@ -12,9 +14,11 @@ export class JobsCreateDto extends CustomFieldsDto {
1214
@ApiProperty()
1315
public action: string;
1416

15-
@IsMongoId()
16-
@ApiProperty()
17-
public concernedTo: Types.ObjectId;
17+
@ValidateNested()
18+
@Type(() => ConcernedToPartDTO)
19+
@IsNotEmpty()
20+
@ApiProperty({ type: ConcernedToPartDTO })
21+
public concernedTo: ConcernedToPartDTO;
1822

1923
@IsMongoId()
2024
@ApiProperty()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2+
import { Document, Types } from 'mongoose';
3+
4+
@Schema({ _id: false })
5+
export class ConcernedToPart extends Document {
6+
@Prop({ type: String, required: true })
7+
public $ref: string;
8+
9+
@Prop({ type: Types.ObjectId, required: true })
10+
public id: Types.ObjectId;
11+
12+
@Prop({ type: String })
13+
public name?: string;
14+
}
15+
16+
export const ConcernedToPartSchema = SchemaFactory.createForClass(ConcernedToPart);

src/core/jobs/_schemas/jobs.schema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
22
import { Document, Types } from 'mongoose';
33
import { AbstractSchema } from '~/_common/abstracts/schemas/abstract.schema';
44
import { JobState } from '../_enums/state.enum';
5+
import { ConcernedToPart, ConcernedToPartSchema } from './_parts/concerned-to.parts.schema';
56

67
export type JobsDocument = Jobs & Document;
78

@@ -20,10 +21,10 @@ export class Jobs extends AbstractSchema {
2021
public action: string;
2122

2223
@Prop({
23-
type: Types.ObjectId,
24+
type: ConcernedToPartSchema,
2425
required: true,
2526
})
26-
public concernedTo?: Types.ObjectId;
27+
public concernedTo?: ConcernedToPart;
2728

2829
@Prop({ type: Types.ObjectId })
2930
public task?: Types.ObjectId;

src/core/jobs/jobs.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import { JobsService } from './jobs.service';
1515
@ApiTags('core')
1616
@Controller('jobs')
1717
export class JobsController extends AbstractController {
18-
protected static readonly projection: PartialProjectionType<JobsDto> = {
18+
protected static readonly projection: PartialProjectionType<JobsDto & { metadata: any }> = {
1919
jobId: 1,
2020
action: 1,
2121
concernedTo: 1,
22+
metadata: 1,
2223
params: 1,
2324
result: 1,
2425
};

0 commit comments

Comments
 (0)