Skip to content

Commit 018a106

Browse files
committed
refact: user interface, model and zod schema
1 parent 94170a6 commit 018a106

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export enum USER_ROLES {
2-
SUPER_ADMIN = 'SUPER_ADMIN',
3-
ADMIN = 'ADMIN',
4-
USER = 'USER',
2+
SUPER_ADMIN = 'Super Admin',
3+
ADMIN = 'Admin',
4+
USER = 'User',
55
}
66

77
export enum USER_STATUS {
8-
ACTIVE = 'ACTIVE',
9-
INACTIVE = 'INACTIVE',
8+
ACTIVE = 'Active',
9+
INACTIVE = 'Inactive',
1010
}

src/app/modules/user/user.controller.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ import { getSingleFilePath } from '../../../shared/getFilePath';
55
import sendResponse from '../../../shared/sendResponse';
66
import { UserService } from './user.service';
77

8-
const createUser = catchAsync(
9-
async (req: Request, res: Response, next: NextFunction) => {
10-
const { ...userData } = req.body;
11-
const result = await UserService.createUserToDB(userData);
12-
13-
sendResponse(res, {
14-
success: true,
15-
statusCode: StatusCodes.OK,
16-
message: 'User created successfully',
17-
data: result,
18-
});
19-
}
20-
);
8+
const createUser = catchAsync(async (req: Request, res: Response) => {
9+
const { ...userData } = req.body;
10+
const result = await UserService.createUserToDB(userData);
11+
12+
sendResponse(res, {
13+
success: true,
14+
statusCode: StatusCodes.OK,
15+
message: 'User created successfully',
16+
data: result,
17+
});
18+
});
2119

2220
const getUserProfile = catchAsync(async (req: Request, res: Response) => {
2321
const user = req.user;
@@ -32,24 +30,22 @@ const getUserProfile = catchAsync(async (req: Request, res: Response) => {
3230
});
3331

3432
//update profile
35-
const updateProfile = catchAsync(
36-
async (req: Request, res: Response, next: NextFunction) => {
37-
const user = req.user;
38-
let image = getSingleFilePath(req.files, 'image');
39-
40-
const data = {
41-
image,
42-
...req.body,
43-
};
44-
const result = await UserService.updateProfileToDB(user, data);
45-
46-
sendResponse(res, {
47-
success: true,
48-
statusCode: StatusCodes.OK,
49-
message: 'Profile updated successfully',
50-
data: result,
51-
});
52-
}
53-
);
33+
const updateProfile = catchAsync(async (req: Request, res: Response) => {
34+
const user = req.user;
35+
let image = getSingleFilePath(req.files, 'image');
36+
37+
const data = {
38+
image,
39+
...req.body,
40+
};
41+
const result = await UserService.updateProfileToDB(user, data);
42+
43+
sendResponse(res, {
44+
success: true,
45+
statusCode: StatusCodes.OK,
46+
message: 'Profile updated successfully',
47+
data: result,
48+
});
49+
});
5450

5551
export const UserController = { createUser, getUserProfile, updateProfile };

src/app/modules/user/user.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { USER_ROLES, USER_STATUS } from './user.constant';
44
export type IUser = {
55
name: string;
66
role: USER_ROLES;
7-
contact: string;
87
email: string;
98
password: string;
10-
location: string;
9+
phone: string;
1110
image?: string;
1211
status: USER_STATUS;
1312
isVerified: boolean;
13+
isDeleted: boolean;
1414
authentication?: {
1515
isResetPassword: boolean;
1616
oneTimeCode: number;

src/app/modules/user/user.model.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ const userSchema = new Schema<IUser, UserModal>(
2929
select: 0,
3030
minlength: 8,
3131
},
32+
phone: {
33+
type: String,
34+
default: '',
35+
},
3236
image: {
3337
type: String,
34-
default: 'https://i.ibb.co/z5YHLV9/profile.png',
38+
default: '',
3539
},
3640
status: {
3741
type: String,
@@ -42,6 +46,10 @@ const userSchema = new Schema<IUser, UserModal>(
4246
type: Boolean,
4347
default: false,
4448
},
49+
isDeleted: {
50+
type: Boolean,
51+
default: false,
52+
},
4553
authentication: {
4654
type: {
4755
isResetPassword: {

src/app/modules/user/user.validation.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
import { z } from 'zod';
2-
import { USER_ROLES, USER_STATUS } from './user.constant';
2+
import { USER_STATUS } from './user.constant';
33

44
const createUserZodSchema = z.object({
55
body: z.object({
66
name: z.string({ required_error: 'Name is required' }),
7-
contact: z.string({ required_error: 'Contact is required' }),
87
email: z.string({ required_error: 'Email is required' }),
98
password: z.string({ required_error: 'Password is required' }),
10-
location: z.string({ required_error: 'Location is required' }),
11-
profile: z.string().optional(),
9+
phone: z.string({ required_error: 'Phone is required' }).optional(),
10+
image: z.string().optional(),
1211
}),
1312
});
1413

1514
const updateUserZodSchema = z.object({
1615
name: z.string().optional(),
17-
contact: z.string().optional(),
1816
email: z.string().optional(),
19-
password: z.string().optional(),
20-
location: z.string().optional(),
17+
phone: z.string().optional(),
2118
image: z.string().optional(),
22-
role: z.nativeEnum(USER_ROLES).optional(),
2319
status: z.nativeEnum(USER_STATUS).optional(),
2420
});
2521

0 commit comments

Comments
 (0)