Skip to content

Commit 5a3693d

Browse files
committed
add user generic module
1 parent 341eafd commit 5a3693d

File tree

7 files changed

+107
-37
lines changed

7 files changed

+107
-37
lines changed

src/apps/user/update-user.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export class UpdateUserDTO {
2+
name: string;
3+
address: string;
4+
photo: string;
5+
}

src/apps/user/user.controller.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Body, Controller, Get, HttpCode, HttpStatus, Post, Req } from '@nestjs/common';
2+
import { Request } from 'express';
3+
import { UseJwtGuard } from 'src/filters/jwt.guard';
4+
import { Response } from 'src/utils';
5+
import { UpdateUserDTO } from './update-user.dto';
6+
import { UserService } from './user.service';
7+
8+
@Controller('user')
9+
@UseJwtGuard()
10+
export class UserController {
11+
12+
constructor(
13+
private userService: UserService,
14+
) {}
15+
16+
@Get()
17+
async getUser(@Req() req: Request) {
18+
19+
return Response.success({
20+
message: "Success showing user data",
21+
data: await this.userService.getUser(req.user),
22+
});
23+
}
24+
25+
@Post()
26+
@HttpCode(HttpStatus.OK)
27+
updateUserData(
28+
@Body() data: UpdateUserDTO,
29+
@Req() req: Request,
30+
) {
31+
32+
const response = this.userService.updateUserData(data, req.user);
33+
}
34+
}

src/apps/user/user.module.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Module } from '@nestjs/common';
2+
import { UserService } from './user.service';
3+
import { UserController } from './user.controller';
4+
import { TypeOrmModule } from '@nestjs/typeorm';
5+
import { User } from 'src/entities/user.entity';
6+
7+
@Module({
8+
imports: [
9+
TypeOrmModule.forFeature([User]),
10+
],
11+
providers: [UserService],
12+
controllers: [UserController]
13+
})
14+
export class UserModule {}

src/apps/user/user.service.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { InjectRepository } from '@nestjs/typeorm';
3+
import { User } from 'src/entities/user.entity';
4+
import { Repository } from 'typeorm';
5+
import { UpdateUserDTO } from './update-user.dto';
6+
7+
@Injectable()
8+
export class UserService {
9+
10+
constructor(
11+
@InjectRepository(User)
12+
private userRepository: Repository<User>,
13+
) { }
14+
15+
16+
async getUser(userAuth: UserInAuth) {
17+
console.log(userAuth);
18+
19+
const getUser = await this.userRepository.findOne({
20+
where: {
21+
id: userAuth.id,
22+
},
23+
select: {
24+
id: true,
25+
code: true,
26+
referral_code: true,
27+
referral_link: true,
28+
uuid: true,
29+
username: true,
30+
name: true,
31+
avatar: true,
32+
phone: true,
33+
phone_verified_at: true,
34+
email: true,
35+
email_verified_at: true,
36+
// password: true,
37+
// updated_at: true,
38+
// created_at: true,
39+
}
40+
})
41+
42+
delete getUser.id;
43+
44+
return getUser;
45+
}
46+
47+
48+
updateUserData(formData: UpdateUserDTO, user: UserInAuth) {
49+
50+
//
51+
52+
}
53+
}
54+
//

src/entities/role.entity.ts

Whitespace-only changes.

src/entities/user-device.entity.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CurrentLoginType } from "src/apps/auth/types";
2-
import { strRandom } from "src/utils";
32
import { Column, CreateDateColumn, Entity, PrimaryColumn, Unique, UpdateDateColumn } from "typeorm";
43

54
@Entity({
@@ -57,5 +56,4 @@ export class UserDevice {
5756

5857
@CreateDateColumn()
5958
created_at: Date;
60-
6159
}

src/entities/user.entity.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,6 @@ export class User {
5353
@Column()
5454
password: string;
5555

56-
@Column({
57-
name: 'telegram_account'
58-
})
59-
telegram_account: string;
60-
61-
@Column({
62-
name: 'telegram_chat_id'
63-
})
64-
telegram_chat_id: string;
65-
66-
@Column({
67-
name: 'telegram_verified_at'
68-
})
69-
telegram_verified_at: Date;
70-
71-
@Column({
72-
name: 'member_id'
73-
})
74-
member_id: number;
75-
76-
@Column({
77-
name: 'member_package_id'
78-
})
79-
member_package_id: number;
80-
81-
@Column({
82-
name: 'member_subscription_id'
83-
})
84-
member_subscription_id: number;
85-
86-
@Column({
87-
name: 'member_status'
88-
})
89-
member_status: string;
90-
9156
@UpdateDateColumn()
9257
updated_at: Date
9358

0 commit comments

Comments
 (0)