diff --git a/apps/server/src/shared/domain/domainobject/user.do.ts b/apps/server/src/shared/domain/domainobject/user.do.ts index 016ad3c29a0..c96e845c926 100644 --- a/apps/server/src/shared/domain/domainobject/user.do.ts +++ b/apps/server/src/shared/domain/domainobject/user.do.ts @@ -14,6 +14,8 @@ export class UserDO extends BaseDO { lastName: string; + preferredName?: string; + roles: RoleReference[]; schoolId: EntityId; @@ -52,6 +54,7 @@ export class UserDO extends BaseDO { this.email = domainObject.email; this.firstName = domainObject.firstName; this.lastName = domainObject.lastName; + this.preferredName = domainObject.preferredName; this.roles = domainObject.roles; this.schoolId = domainObject.schoolId; this.ldapDn = domainObject.ldapDn; diff --git a/apps/server/src/shared/domain/entity/user.entity.spec.ts b/apps/server/src/shared/domain/entity/user.entity.spec.ts index c12f0960475..8615ec51f1a 100644 --- a/apps/server/src/shared/domain/entity/user.entity.spec.ts +++ b/apps/server/src/shared/domain/entity/user.entity.spec.ts @@ -30,6 +30,7 @@ describe('User Entity', () => { const user = new User({ firstName: 'John', lastName: 'Cale', + preferredName: 'Johnny', email: 'john.cale@velvet.underground', school, roles: [], diff --git a/apps/server/src/shared/domain/entity/user.entity.ts b/apps/server/src/shared/domain/entity/user.entity.ts index cfb27773c5b..aa659c7f02b 100644 --- a/apps/server/src/shared/domain/entity/user.entity.ts +++ b/apps/server/src/shared/domain/entity/user.entity.ts @@ -14,6 +14,7 @@ export interface UserProperties { email: string; firstName: string; lastName: string; + preferredName?: string; school: SchoolEntity; roles: Role[]; ldapDn?: string; @@ -59,6 +60,9 @@ export class User extends BaseEntityWithTimestamps implements EntityWithSchool { @Property() lastName: string; + @Property({ nullable: true }) + preferredName?: string; + @Index() @ManyToMany({ fieldName: 'roles', entity: () => Role }) roles = new Collection(this); @@ -135,6 +139,7 @@ export class User extends BaseEntityWithTimestamps implements EntityWithSchool { super(); this.firstName = props.firstName; this.lastName = props.lastName; + this.preferredName = props.preferredName; this.email = props.email; this.school = props.school; this.roles.set(props.roles); diff --git a/apps/server/src/shared/repo/user/user-do.repo.integration.spec.ts b/apps/server/src/shared/repo/user/user-do.repo.integration.spec.ts index 20f1ecba378..0b6cc396d95 100644 --- a/apps/server/src/shared/repo/user/user-do.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/user/user-do.repo.integration.spec.ts @@ -314,6 +314,7 @@ describe('UserRepo', () => { email: testEntity.email, firstName: testEntity.firstName, lastName: testEntity.lastName, + preferredName: testEntity.preferredName, schoolId: testEntity.school.id, roles: [ { @@ -348,6 +349,7 @@ describe('UserRepo', () => { email: 'email@email.email', firstName: 'firstName', lastName: 'lastName', + preferredName: 'preferredName', schoolId: new ObjectId().toHexString(), ldapDn: 'ldapDn', externalId: 'externalId', @@ -368,6 +370,7 @@ describe('UserRepo', () => { email: testDO.email, firstName: testDO.firstName, lastName: testDO.lastName, + preferredName: testDO.preferredName, // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment school: expect.objectContaining>({ id: testDO.schoolId }), // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment diff --git a/apps/server/src/shared/repo/user/user-do.repo.ts b/apps/server/src/shared/repo/user/user-do.repo.ts index 2f894280d0a..791aa9a5bb5 100644 --- a/apps/server/src/shared/repo/user/user-do.repo.ts +++ b/apps/server/src/shared/repo/user/user-do.repo.ts @@ -116,6 +116,7 @@ export class UserDORepo extends BaseDORepo { email: entity.email, firstName: entity.firstName, lastName: entity.lastName, + preferredName: entity.preferredName, roles: [], schoolId: entity.school.id, ldapDn: entity.ldapDn, @@ -147,6 +148,7 @@ export class UserDORepo extends BaseDORepo { email: entityDO.email, firstName: entityDO.firstName, lastName: entityDO.lastName, + preferredName: entityDO.preferredName, school: this._em.getReference(SchoolEntity, entityDO.schoolId), roles: entityDO.roles.map((roleRef: RoleReference) => this._em.getReference(Role, roleRef.id)), ldapDn: entityDO.ldapDn, diff --git a/apps/server/src/shared/repo/user/user.repo.integration.spec.ts b/apps/server/src/shared/repo/user/user.repo.integration.spec.ts index 4dba77016ac..8806b77dccf 100644 --- a/apps/server/src/shared/repo/user/user.repo.integration.spec.ts +++ b/apps/server/src/shared/repo/user/user.repo.integration.spec.ts @@ -64,6 +64,7 @@ describe('user repo', () => { 'firstNameSearchValues', 'lastName', 'lastNameSearchValues', + 'preferredName', 'lastSyncedAt', 'email', 'emailSearchValues', @@ -197,6 +198,7 @@ describe('user repo', () => { 'firstNameSearchValues', 'lastName', 'lastNameSearchValues', + 'preferredName', 'lastSyncedAt', 'email', 'emailSearchValues', diff --git a/src/services/user/model/user.schema.js b/src/services/user/model/user.schema.js index b8d26b75b42..3ea388b16e9 100644 --- a/src/services/user/model/user.schema.js +++ b/src/services/user/model/user.schema.js @@ -32,6 +32,7 @@ const userSchema = new Schema( firstName: { type: String, required: true }, firstNameSearchValues: { type: Schema.Types.Array }, + preferredName: { type: String }, middleName: { type: String }, lastName: { type: String, required: true }, lastNameSearchValues: { type: Schema.Types.Array },