Skip to content

Commit 188589f

Browse files
committed
correction check uid et email
1 parent 003e18d commit 188589f

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/management/identities/abstract-identities.service.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,17 @@ export abstract class AbstractIdentitiesService extends AbstractServiceSchema {
230230
}
231231
}
232232

233-
protected async checkMail(data): Promise<boolean> {
233+
protected async checkMail(identity,data): Promise<boolean> {
234234
let dataDup = 0;
235235
if (data.inetOrgPerson.hasOwnProperty('mail') && data.inetOrgPerson.mail !== '') {
236-
const id = new Types.ObjectId(data['_id']);
237-
const f: any = { '_id': { $ne: id }, 'inetOrgPerson.mail': data.inetOrgPerson.mail };
238-
dataDup = await this._model.countDocuments(f).exec()
236+
if (identity){
237+
const f: any = { '_id': { $ne: identity._id }, 'inetOrgPerson.mail': identity.inetOrgPerson.mail };
238+
dataDup = await this._model.countDocuments(f).exec()
239+
}else{
240+
const f: any = { 'inetOrgPerson.mail': data.inetOrgPerson.mail };
241+
dataDup = await this._model.countDocuments(f).exec()
242+
}
243+
239244
}
240245
if (dataDup > 0) {
241246
return false
@@ -244,11 +249,16 @@ export abstract class AbstractIdentitiesService extends AbstractServiceSchema {
244249
}
245250
}
246251

247-
protected async checkUid(data): Promise<boolean> {
252+
protected async checkUid(identity,data): Promise<boolean> {
248253
let dataDup = 0;
249-
const id = new Types.ObjectId(data['_id']);
250-
const f: any = { '_id': { $ne: id }, 'inetOrgPerson.uid': data.inetOrgPerson.uid };
251-
dataDup = await this._model.countDocuments(f).exec()
254+
if (identity){
255+
const f: any = { '_id': { $ne: identity._id }, 'inetOrgPerson.uid': identity.inetOrgPerson.uid };
256+
dataDup = await this._model.countDocuments(f).exec()
257+
}else{
258+
const f: any = { 'inetOrgPerson.uid': data.inetOrgPerson.uid };
259+
dataDup = await this._model.countDocuments(f).exec()
260+
}
261+
252262
if (dataDup > 0) {
253263
return false
254264
} else {

src/management/identities/identities-upsert.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ export class IdentitiesUpsertService extends AbstractIdentitiesService {
6161
this.logger.log(`${logPrefix} Starting additionalFields validation.`);
6262
let validations = await this._validation.validate(data.additionalFields,true);
6363
//validation email and uid
64-
if (await this.checkMail(data) === false) {
64+
if (await this.checkMail(identity,data) === false) {
6565
validations['inetOrgPerson.mail'] = "Email déjà présent dans une autre identité"
6666
}
67-
if (await this.checkUid(data) === false) {
67+
if (await this.checkUid(identity,data) === false) {
6868
validations['inetOrgPerson.uid'] = "Uid déjà présent dans une autre identité"
6969
}
7070
this.logger.log(`${logPrefix} AdditionalFields validation successful.`);
@@ -73,17 +73,17 @@ export class IdentitiesUpsertService extends AbstractIdentitiesService {
7373
crushedUpdate['additionalFields.validations'] = {};
7474
} catch (error) {
7575
data = this.handleValidationError(error, data, logPrefix);
76-
crushedUpdate['state'] = data.state;
76+
crushedUpdate['state'] = IdentityState.TO_COMPLETE;
7777
crushedUpdate['additionalFields.validations'] = data.additionalFields.validations;
7878
}
7979
//validation email and uid
80-
if (await this.checkMail(data) === false){
80+
if (await this.checkMail(identity,data) === false){
8181
crushedUpdate['additionalFields.validations']['inetOrgPerson']={mail:"Email déjà présent dans une autre identité"}
82-
crushedUpdate['state'] = data.state;
82+
crushedUpdate['state'] = IdentityState.TO_COMPLETE;
8383
}
84-
if (await this.checkUid(data) === false){
84+
if (await this.checkUid(identity,data) === false){
8585
crushedUpdate['additionalFields.validations']['inetOrgPerson']= {uid:"Uid déjà présent dans une autre identité"}
86-
crushedUpdate['state'] = data.state;
86+
crushedUpdate['state'] = IdentityState.TO_COMPLETE;
8787
}
8888

8989
const fingerprint = await this.previewFingerprint(

0 commit comments

Comments
 (0)