Skip to content

Commit

Permalink
fix: adjusment to send user informations on login
Browse files Browse the repository at this point in the history
  • Loading branch information
Daaaiii committed Nov 30, 2023
1 parent 72b36a4 commit 7090dc3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/modules/account/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ export class AccountController {
@ApiResponse(responses.unauthorized)
@ApiResponse(responses.internalError)
async login(@Body() { email, password }: LoginDto) {
const { token, refresh } = await this.accountService.login(email, password);
const { token, refresh, user } = await this.accountService.login(
email,
password,
);

return {
message: 'Acesso permitido',
data: {
accessToken: token,
refreshToken: refresh,
user: user,
},
};
}
Expand Down
6 changes: 5 additions & 1 deletion src/modules/account/account.entity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export type GetCredentialIdByEmailOutput = Pick<
Credential,
'id' | 'password'
> & {
parentProfile: Pick<ParentProfile, 'id' | 'fullname'>;
parentProfile: Pick<ParentProfile, 'id' | 'fullname'> & {
childrens: Array<
Pick<ChildrenProfile, 'id' | 'fullname' | 'birthdate' | 'gender'>
>;
};
};

export type getCredentialIdByRecoveryTokenInput = {
Expand Down
8 changes: 8 additions & 0 deletions src/modules/account/account.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export class AccountRepository {
select: {
id: true,
fullname: true,
childrens: {
select: {
id: true,
fullname: true,
gender: true,
birthdate: true,
},
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions src/modules/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ export class AccountService {
cid: credential.id,
pid: credential.parentProfile.id,
};
const user = {
pid: credential.parentProfile.id,
parentName: credential.parentProfile.fullname,
childrens: credential.parentProfile.childrens,
};

const [token, refresh] = await Promise.all([
this.createAuthToken(tokenPayload, 'access'),
Expand All @@ -252,6 +257,7 @@ export class AccountService {
return {
token,
refresh,
user,
};
}
}
8 changes: 8 additions & 0 deletions test/unit/account.service.stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@ export const getCredentialOutput: GetCredentialIdByEmailOutput = {
parentProfile: {
id: faker.string.uuid(),
fullname: faker.person.fullName(),
childrens: [
{
id: faker.number.int(),
fullname: faker.person.fullName(),
birthdate: faker.date.birthdate(),
gender: ('male' || 'female') as Genders,
},
],
},
};

0 comments on commit 7090dc3

Please sign in to comment.