Skip to content

Commit

Permalink
feat: schema fixes, private user create
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhaev26 committed Jan 25, 2025
1 parent f2e1fc3 commit 8aac55f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
Binary file added dump.rdb
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function bootstrap() {
const httpServer = app.getHttpServer();
app.useWebSocketAdapter(new IoAdapter(httpServer));

const port = process.env.PORT || 3000;
const port = process.env.PORT || 3030;
await app.listen(port);
}

Expand Down
1 change: 1 addition & 0 deletions src/services/apis/auth/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class AuthGuard implements CanActivate {
const payload = await this.jwtService.verifyAsync(token, {
secret: jwtConstants.secret,
});
console.log({ payload });
const user = await this.usersService._get(payload.sub.id);
// 💡 We're assigning the payload to the request object here
// so that we can access it in our route handlers
Expand Down
7 changes: 6 additions & 1 deletion src/services/apis/users/schemas/users.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ export class Users extends SoftDeleteSchema {
})
lastName: string;

@Prop({
type: Number,
enum: [1, 4096],
})
type: number;

@Prop({
type: String,
trim: true,
required: true,
unique: true,
index: true,
match: /^[0-9]{10}$/,
})
phone: string;

Expand Down
22 changes: 19 additions & 3 deletions src/services/apis/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,29 @@ export class UsersController {
return await this.usersService._get(id, query);
}

@Public()
@Post()
async create(@Body() createUsersDto: Users) {
async create(@Body() createUsersDto: Users, @User() users: Users) {
/**
* @todo use zod for validations...
*/
const saltOrRounds = 10;
console.log({ users });
if (users.type === 4096) {
const password = await bcrypt.hash(createUsersDto.password, saltOrRounds);

const user = (await this.usersService._create({
...createUsersDto,
password,
})) as Users;

const sanitizedUser = this.usersService.sanitizeUser(user);
const payload = { sub: { id: user._id }, user };

return {
user: sanitizedUser,
accessToken: await this.jwtService.signAsync(payload),
};
}
if (!createUsersDto.email || !createUsersDto['otp']) {
throw new BadRequestException('Email or OTP not provided!');
}
Expand All @@ -53,7 +70,6 @@ export class UsersController {
true, // removeEntryAfterCheck
);

const saltOrRounds = 10;
const password = await bcrypt.hash(createUsersDto.password, saltOrRounds);

const user = (await this.usersService._create({
Expand Down

0 comments on commit 8aac55f

Please sign in to comment.