Skip to content

Commit cc25919

Browse files
committed
Updated user interface and kodel
1 parent 3a23d29 commit cc25919

File tree

9 files changed

+28
-16
lines changed

9 files changed

+28
-16
lines changed

src/DB/seedAdmin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { USER_ROLES } from '../app/modules/user/user.constant';
12
import { User } from '../app/modules/user/user.model';
23
import config from '../config';
3-
import { USER_ROLES } from '../enums/user';
44
import { logger } from '../shared/logger';
55

66
const payload = {
77
name: 'Administrator',
88
email: config.super_admin.email,
99
role: USER_ROLES.SUPER_ADMIN,
1010
password: config.super_admin.password,
11-
verified: true,
11+
isVerified: true,
1212
};
1313

1414
export const seedSuperAdmin = async () => {

src/app/modules/auth/auth.route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import express from 'express';
2-
import { USER_ROLES } from '../../../enums/user';
32
import auth from '../../middlewares/auth';
43
import validateRequest from '../../middlewares/validateRequest';
54
import { AuthController } from './auth.controller';
65
import { AuthValidation } from './auth.validation';
6+
import { USER_ROLES } from '../user/user.constant';
77
const router = express.Router();
88

99
router.post(

src/app/modules/auth/auth.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import cryptoToken from '../../../util/cryptoToken';
1616
import generateOTP from '../../../util/generateOTP';
1717
import { ResetToken } from '../resetToken/resetToken.model';
1818
import { User } from '../user/user.model';
19+
import { USER_STATUS } from '../user/user.constant';
1920

2021
//login
2122
const loginUserFromDB = async (payload: ILoginData) => {
@@ -26,15 +27,15 @@ const loginUserFromDB = async (payload: ILoginData) => {
2627
}
2728

2829
//check verified and status
29-
if (!isExistUser.verified) {
30+
if (!isExistUser.isVerified) {
3031
throw new ApiError(
3132
StatusCodes.BAD_REQUEST,
3233
'Please verify your account, then try to login again'
3334
);
3435
}
3536

3637
//check user status
37-
if (isExistUser.status === 'delete') {
38+
if (isExistUser.status !== USER_STATUS.ACTIVE) {
3839
throw new ApiError(
3940
StatusCodes.BAD_REQUEST,
4041
'You don’t have permission to access this content.It looks like your account has been deactivated.'
@@ -113,10 +114,13 @@ const verifyEmailToDB = async (payload: IVerifyEmail) => {
113114
let message;
114115
let data;
115116

116-
if (!isExistUser.verified) {
117+
if (!isExistUser.isVerified) {
117118
await User.findOneAndUpdate(
118119
{ _id: isExistUser._id },
119-
{ verified: true, authentication: { oneTimeCode: null, expireAt: null } }
120+
{
121+
isVerified: true,
122+
authentication: { oneTimeCode: null, expireAt: null },
123+
}
120124
);
121125
message = 'Email verify successfully';
122126
} else {

src/enums/user.ts renamed to src/app/modules/user/user.constant.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ export enum USER_ROLES {
33
ADMIN = 'ADMIN',
44
USER = 'USER',
55
}
6+
7+
export enum USER_STATUS {
8+
ACTIVE = 'ACTIVE',
9+
INACTIVE = 'INACTIVE',
10+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Model } from 'mongoose';
2-
import { USER_ROLES } from '../../../enums/user';
2+
import { USER_ROLES, USER_STATUS } from './user.constant';
33

44
export type IUser = {
55
name: string;
@@ -9,8 +9,8 @@ export type IUser = {
99
password: string;
1010
location: string;
1111
image?: string;
12-
status: 'active' | 'delete';
13-
verified: boolean;
12+
status: USER_STATUS;
13+
isVerified: boolean;
1414
authentication?: {
1515
isResetPassword: boolean;
1616
oneTimeCode: number;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import bcrypt from 'bcrypt';
22
import { StatusCodes } from 'http-status-codes';
33
import { model, Schema } from 'mongoose';
44
import config from '../../../config';
5-
import { USER_ROLES } from '../../../enums/user';
65
import ApiError from '../../../errors/ApiError';
76
import { IUser, UserModal } from './user.interface';
7+
import { USER_ROLES, USER_STATUS } from './user.constant';
88

99
const userSchema = new Schema<IUser, UserModal>(
1010
{
@@ -35,10 +35,10 @@ const userSchema = new Schema<IUser, UserModal>(
3535
},
3636
status: {
3737
type: String,
38-
enum: ['active', 'delete'],
39-
default: 'active',
38+
enum: Object.values(USER_STATUS),
39+
default: USER_STATUS.ACTIVE,
4040
},
41-
verified: {
41+
isVerified: {
4242
type: Boolean,
4343
default: false,
4444
},

src/app/modules/user/user.route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import express, { NextFunction, Request, Response } from 'express';
2-
import { USER_ROLES } from '../../../enums/user';
32
import auth from '../../middlewares/auth';
43
import validateRequest from '../../middlewares/validateRequest';
54
import { UserController } from './user.controller';
65
import { UserValidation } from './user.validation';
76
import fileUploadHandler from '../../middlewares/fileUploadHandler';
7+
import { USER_ROLES } from './user.constant';
88
const router = express.Router();
99

1010
router

src/app/modules/user/user.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { StatusCodes } from 'http-status-codes';
22
import { JwtPayload } from 'jsonwebtoken';
3-
import { USER_ROLES } from '../../../enums/user';
43
import ApiError from '../../../errors/ApiError';
54
import { emailHelper } from '../../../helpers/emailHelper';
65
import { emailTemplate } from '../../../shared/emailTemplate';
76
import unlinkFile from '../../../shared/unlinkFile';
87
import generateOTP from '../../../util/generateOTP';
98
import { IUser } from './user.interface';
109
import { User } from './user.model';
10+
import { USER_ROLES } from './user.constant';
1111

1212
const createUserToDB = async (payload: Partial<IUser>): Promise<IUser> => {
1313
//set role

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

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

34
const createUserZodSchema = z.object({
45
body: z.object({
@@ -18,6 +19,8 @@ const updateUserZodSchema = z.object({
1819
password: z.string().optional(),
1920
location: z.string().optional(),
2021
image: z.string().optional(),
22+
role: z.nativeEnum(USER_ROLES).optional(),
23+
status: z.nativeEnum(USER_STATUS).optional(),
2124
});
2225

2326
export const UserValidation = {

0 commit comments

Comments
 (0)