Skip to content

Commit 8aac55f

Browse files
committed
feat: schema fixes, private user create
1 parent f2e1fc3 commit 8aac55f

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

dump.rdb

375 Bytes
Binary file not shown.

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function bootstrap() {
1313
const httpServer = app.getHttpServer();
1414
app.useWebSocketAdapter(new IoAdapter(httpServer));
1515

16-
const port = process.env.PORT || 3000;
16+
const port = process.env.PORT || 3030;
1717
await app.listen(port);
1818
}
1919

src/services/apis/auth/auth.guard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class AuthGuard implements CanActivate {
3737
const payload = await this.jwtService.verifyAsync(token, {
3838
secret: jwtConstants.secret,
3939
});
40+
console.log({ payload });
4041
const user = await this.usersService._get(payload.sub.id);
4142
// 💡 We're assigning the payload to the request object here
4243
// so that we can access it in our route handlers

src/services/apis/users/schemas/users.schema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ export class Users extends SoftDeleteSchema {
3535
})
3636
lastName: string;
3737

38+
@Prop({
39+
type: Number,
40+
enum: [1, 4096],
41+
})
42+
type: number;
43+
3844
@Prop({
3945
type: String,
4046
trim: true,
4147
required: true,
4248
unique: true,
4349
index: true,
44-
match: /^[0-9]{10}$/,
4550
})
4651
phone: string;
4752

src/services/apis/users/users.controller.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,29 @@ export class UsersController {
3535
return await this.usersService._get(id, query);
3636
}
3737

38-
@Public()
3938
@Post()
40-
async create(@Body() createUsersDto: Users) {
39+
async create(@Body() createUsersDto: Users, @User() users: Users) {
4140
/**
4241
* @todo use zod for validations...
4342
*/
43+
const saltOrRounds = 10;
44+
console.log({ users });
45+
if (users.type === 4096) {
46+
const password = await bcrypt.hash(createUsersDto.password, saltOrRounds);
47+
48+
const user = (await this.usersService._create({
49+
...createUsersDto,
50+
password,
51+
})) as Users;
52+
53+
const sanitizedUser = this.usersService.sanitizeUser(user);
54+
const payload = { sub: { id: user._id }, user };
55+
56+
return {
57+
user: sanitizedUser,
58+
accessToken: await this.jwtService.signAsync(payload),
59+
};
60+
}
4461
if (!createUsersDto.email || !createUsersDto['otp']) {
4562
throw new BadRequestException('Email or OTP not provided!');
4663
}
@@ -53,7 +70,6 @@ export class UsersController {
5370
true, // removeEntryAfterCheck
5471
);
5572

56-
const saltOrRounds = 10;
5773
const password = await bcrypt.hash(createUsersDto.password, saltOrRounds);
5874

5975
const user = (await this.usersService._create({

0 commit comments

Comments
 (0)