Skip to content

Commit

Permalink
update user schema
Browse files Browse the repository at this point in the history
  • Loading branch information
wermarter committed Jan 18, 2024
1 parent 78727a8 commit 70b0a81
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
7 changes: 4 additions & 3 deletions apps/hcdc-access-service/src/domain/entity/user/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { Branch } from '../branch'

export type User = BaseEntity & {
username: string
password: string
passwordHash: string

name: string
phoneNumber: string

branchId: string
branch?: Branch | null
branchIds: string[]
branches?: (Branch | null)[]

// roles: string[] | Role[]
// inlinePermissions: string[] | Permission[]
Expand Down
8 changes: 4 additions & 4 deletions apps/hcdc-access-service/src/domain/entity/user/example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exampleMongoObjectId } from '@diut/nest-core'
import { exampleMongoObjectIds } from '@diut/nest-core'

import { EntityExample } from '../base-entity'
import { User } from './entity'
Expand All @@ -16,9 +16,9 @@ export const exampleUser: EntityExample<User> = {
example: '1234567890',
description: 'phoneNumber',
},
password: {
passwordHash: {
example: 'hashed_password',
description: 'password',
description: 'passwordHash',
},
branchId: exampleMongoObjectId,
branchIds: exampleMongoObjectIds,
}
2 changes: 1 addition & 1 deletion apps/hcdc-access-service/src/domain/use-case/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class AuthLoginUseCase {
throw new EAuthnLoginInvalidUsername()
}

const isCorrect = await argon2.verify(user.password, password)
const isCorrect = await argon2.verify(user.passwordHash, password)
if (!isCorrect) {
throw new EAuthnLoginInvalidPassword()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class AuthPopulateContextUseCase {
async execute(input: AuthPayload): Promise<AuthContextData> {
const user = await this.userRepository.findOne({
filter: { _id: input.userId },
populates: [{ path: 'branch' }],
populates: [{ path: 'branches' }],
})

if (!user) {
Expand Down
14 changes: 7 additions & 7 deletions apps/hcdc-access-service/src/infrastructure/mongo/user/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { BranchSchema } from '../branch'
...baseSchemaOptions,
collection: COLLECTION.USER,
virtuals: {
branch: {
branches: {
options: {
ref: BranchSchema.name,
localField: 'branchId',
localField: 'branchIds',
foreignField: '_id',
justOne: true,
justOne: false,
},
},
},
Expand All @@ -24,16 +24,16 @@ export class UserSchema extends BaseSchema {
username: string

@Prop({ required: true })
password: string
passwordHash: string

@Prop({ required: true })
name: string

@Prop({ required: true })
phoneNumber: string

@Prop({ required: true, type: Types.ObjectId })
branchId: string
@Prop({ required: true, type: [Types.ObjectId] })
branchIds: string[]

branch?: BranchSchema | null
branches?: (BranchSchema | null)[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class AuthLoginRequestDto {
@IsNotEmpty()
username: string

@ApiProperty(exampleUser.password)
@ApiProperty(exampleUser.passwordHash)
@IsString()
@IsNotEmpty()
password: string
Expand Down
5 changes: 5 additions & 0 deletions libs/nest-core/src/mongo/mongo.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const exampleMongoObjectId = {
description: 'MongoDB ObjectId',
}

export const exampleMongoObjectIds = {
example: ['634180269de1f07e47bbf494'],
description: 'MongoDB ObjectIds',
}

export const exampleDate = {
format: 'date-time',
example: '2018-03-20T09:12:28Z',
Expand Down

0 comments on commit 70b0a81

Please sign in to comment.