Skip to content

Commit

Permalink
N21-2026 preferred name (#5295)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrikallab authored Oct 16, 2024
1 parent b4dc671 commit e67442f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/server/src/shared/domain/domainobject/user.do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class UserDO extends BaseDO {

lastName: string;

preferredName?: string;

roles: RoleReference[];

schoolId: EntityId;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/shared/domain/entity/user.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('User Entity', () => {
const user = new User({
firstName: 'John',
lastName: 'Cale',
preferredName: 'Johnny',
email: '[email protected]',
school,
roles: [],
Expand Down
5 changes: 5 additions & 0 deletions apps/server/src/shared/domain/entity/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface UserProperties {
email: string;
firstName: string;
lastName: string;
preferredName?: string;
school: SchoolEntity;
roles: Role[];
ldapDn?: string;
Expand Down Expand Up @@ -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<Role>(this);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ describe('UserRepo', () => {
email: testEntity.email,
firstName: testEntity.firstName,
lastName: testEntity.lastName,
preferredName: testEntity.preferredName,
schoolId: testEntity.school.id,
roles: [
{
Expand Down Expand Up @@ -348,6 +349,7 @@ describe('UserRepo', () => {
email: '[email protected]',
firstName: 'firstName',
lastName: 'lastName',
preferredName: 'preferredName',
schoolId: new ObjectId().toHexString(),
ldapDn: 'ldapDn',
externalId: 'externalId',
Expand All @@ -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<Partial<SchoolEntity>>({ id: testDO.schoolId }),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/shared/repo/user/user-do.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class UserDORepo extends BaseDORepo<UserDO, User> {
email: entity.email,
firstName: entity.firstName,
lastName: entity.lastName,
preferredName: entity.preferredName,
roles: [],
schoolId: entity.school.id,
ldapDn: entity.ldapDn,
Expand Down Expand Up @@ -147,6 +148,7 @@ export class UserDORepo extends BaseDORepo<UserDO, User> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('user repo', () => {
'firstNameSearchValues',
'lastName',
'lastNameSearchValues',
'preferredName',
'lastSyncedAt',
'email',
'emailSearchValues',
Expand Down Expand Up @@ -197,6 +198,7 @@ describe('user repo', () => {
'firstNameSearchValues',
'lastName',
'lastNameSearchValues',
'preferredName',
'lastSyncedAt',
'email',
'emailSearchValues',
Expand Down
1 change: 1 addition & 0 deletions src/services/user/model/user.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit e67442f

Please sign in to comment.