Skip to content

Commit 6d7e17d

Browse files
committed
Refactor IdentitiesSchema to add unique index on employeeNumber and employeeType
1 parent 46b2ae1 commit 6d7e17d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/management/identities/_schemas/identities.schema.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IdentityLifecycle } from './../_enums/lifecycle.enum';
22
import { inetOrgPerson, inetOrgPersonSchema } from './_parts/inetOrgPerson.part';
33
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
4-
import {Document, Types} from 'mongoose';
4+
import { Document, Types } from 'mongoose';
55
import { AbstractSchema } from '~/_common/abstracts/schemas/abstract.schema';
66
import { IdentityState } from '../_enums/states.enum';
77
import { AdditionalFieldsPart, AdditionalFieldsPartSchema } from './_parts/additionalFields.part.schema';
@@ -53,11 +53,16 @@ export class Identities extends AbstractSchema {
5353
public destFusionId: Types.ObjectId;
5454
}
5555

56-
export const IdentitiesSchema = SchemaFactory.createForClass(Identities).plugin(AutoIncrementPlugin, <AutoIncrementPluginOptions>{
57-
incrementBy: 1,
58-
field: 'inetOrgPerson.employeeNumber',
59-
startAt: 1,
60-
rules: (ctx) => {
61-
return ctx.inetOrgPerson.employeeType === 'LOCAL';
62-
},
63-
});
56+
export const IdentitiesSchema = SchemaFactory.createForClass(Identities)
57+
.plugin(AutoIncrementPlugin, <AutoIncrementPluginOptions>{
58+
incrementBy: 1,
59+
field: 'inetOrgPerson.employeeNumber',
60+
startAt: 1,
61+
rules: (ctx) => {
62+
return ctx.inetOrgPerson.employeeType === 'LOCAL';
63+
},
64+
})
65+
.index(
66+
{ 'inetOrgPerson.employeeNumber': 1, 'inetOrgPerson.employeeType': 1 },
67+
{ unique: true },
68+
);

0 commit comments

Comments
 (0)