Skip to content

Commit f47ad99

Browse files
feat user added
1 parent 466bd68 commit f47ad99

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

src/users/dto/create-user.dto.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
import { IsNotEmpty, IsNumberString, IsStrongPassword } from 'class-validator';
1+
import {
2+
IsNotEmpty,
3+
IsNumberString,
4+
IsOptional,
5+
IsStrongPassword,
6+
} from "class-validator";
27

38
export class CreateUserDto {
49
@IsNumberString()
510
@IsNotEmpty()
6-
username : String
7-
first_name : String
8-
last_name : String
9-
@IsStrongPassword({ minLength: 8, minLowercase: 1, minNumbers: 1, minSymbols: 1, minUppercase: 1})
10-
password : String
11-
password_reset_code : String
12-
email : String
13-
email_code : String
14-
activation_code: string
11+
username: String;
12+
first_name: String;
13+
last_name: String;
14+
@IsStrongPassword({
15+
minLength: 8,
16+
minLowercase: 1,
17+
minNumbers: 1,
18+
minSymbols: 1,
19+
minUppercase: 1,
20+
})
21+
password: String;
22+
password_reset_code?: String;
23+
email: String;
24+
email_code?: String;
25+
@IsOptional()
26+
activation_code?: string;
27+
@IsOptional()
28+
createdAt?: Date;
29+
@IsOptional()
30+
updatedAt?: Date;
1531
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2+
import { HydratedDocument, now } from 'mongoose';
3+
4+
export type UserDocument = HydratedDocument<RefresToken>;
5+
6+
@Schema({timestamps: true})
7+
export class RefresToken {
8+
@Prop({ type : String })
9+
user_id: string;
10+
@Prop({ type : Boolean })
11+
is_revoked: Boolean;
12+
@Prop({ type : Date })
13+
expires: Date;
14+
@Prop({default: now()})
15+
createdAt: Date;
16+
@Prop({default: now()})
17+
updatedAt: Date;
18+
}
19+
20+
export const UserSchema = SchemaFactory.createForClass(RefresToken);

src/users/schemas/user.schema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
2-
import { HydratedDocument } from 'mongoose';
2+
import { HydratedDocument, now } from 'mongoose';
33

44
export type UserDocument = HydratedDocument<User>;
55

6-
@Schema()
6+
@Schema({timestamps: true})
77
export class User {
88
@Prop({ type : String })
99
username: string;
@@ -21,6 +21,10 @@ export class User {
2121
password: string;
2222
@Prop({ type : String })
2323
password_reset_code
24+
@Prop({default: now()})
25+
createdAt: Date;
26+
@Prop({default: now()})
27+
updatedAt: Date;
2428
}
2529

2630
export const UserSchema = SchemaFactory.createForClass(User);

src/users/users.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { userData } from 'src/interface/common';
1010
export class UserService {
1111
constructor(@InjectModel(User.name) private readonly userModel: Model<User>) {}
1212

13-
async create(createUserDto: CreateUserDto): Promise<User> {
13+
async create(createUserDto: CreateUserDto): Promise<CreateUserDto> {
1414
const saltOrRounds = 10;
1515
const hashedPassword = await bcrypt.hash(createUserDto.password, saltOrRounds);
1616
createUserDto.password = hashedPassword;
17-
const createdCat = await this.userModel.create(createUserDto);
18-
return createdCat;
17+
const createduUser = await this.userModel.create(createUserDto);
18+
return createduUser;
1919
}
2020

2121
async findAll(): Promise<userData[]> {
@@ -30,9 +30,9 @@ export class UserService {
3030
return this.userModel.findOne({ email: email }).exec();
3131
}
3232
async delete(id: string) {
33-
const deletedCat = await this.userModel
33+
const deletedUser = await this.userModel
3434
.findByIdAndRemove({ _id: id })
3535
.exec();
36-
return deletedCat;
36+
return deletedUser;
3737
}
3838
}

0 commit comments

Comments
 (0)