Skip to content

Commit

Permalink
fix(user): correct user interface and added user schema
Browse files Browse the repository at this point in the history
  • Loading branch information
KostaD02 committed Aug 16, 2023
1 parent b3b42db commit 8072894
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { MongooseModule } from '@nestjs/mongoose';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ShopModule } from './modules';
import { ShopModule, UserModule } from './modules';
import { ExceptionService } from './shared';

@Module({
imports: [
ConfigModule.forRoot(),
MongooseModule.forRoot(process.env.DATABASE_URL),
ShopModule,
UserModule,
],
controllers: [AppController],
providers: [AppService, ExceptionService],
Expand Down
3 changes: 2 additions & 1 deletion src/data/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Gender } from 'src/enums';
import { Gender, UserRole } from 'src/enums';
import { User } from 'src/interfaces';
// dummy data before initial database
// TODO: Fill later
Expand All @@ -11,6 +11,7 @@ export const USERS: User[] = [
email: 'johndoe@gmail.com',
password: 'password123',
address: 'nowhere',
role: UserRole.Default,
phone: '+123456789',
zipcode: '1234',
avatar: 'https://api.dicebear.com/6.x/lorelei/svg?flip=false',
Expand Down
7 changes: 6 additions & 1 deletion src/enums/exceptions.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ export enum ProductExceptionKeys {
}

export enum GlobalExceptionKeys {
IncorrectMongooseID = 'error.incorrect_mongoose_id',
IncorrectMongooseID = 'errors.incorrect_mongoose_id',
PageIndexNotNumber = 'errors.page_index.not_number',
PageIndexTooLow = 'errors.page_index.too_low',
PageSizeNotNumber = 'errors.page_size.not_number',
PageSizeTooLow = 'errors.page_size.too_low',
PageSizeTooHigh = 'errors.page_size.too_high',
EndPointNotFound = 'errors.endpoint_not_found',
}

export enum AuthExpectionKeys {
IncorrectEmailOrPassword = 'errors.incorrect_email_or_password',
EmailInUse = 'errors.email_in_use',
}
1 change: 1 addition & 0 deletions src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './currency.enum';
export * from './gender.enum';
export * from './exceptions.enum';
export * from './sort.enum';
export * from './role.enum';
5 changes: 5 additions & 0 deletions src/enums/role.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum UserRole {
Default = 'default',
Moderator = 'moderator', // TODO: should we need it for creating data ?
Admin = 'admin',
}
3 changes: 2 additions & 1 deletion src/interfaces/user.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Gender } from '../enums';
import { Gender, UserRole } from '../enums';

export interface User {
_id: string;
Expand All @@ -8,6 +8,7 @@ export interface User {
email: string;
password: string;
address: string;
role: UserRole;
phone: string;
zipcode: string;
avatar: string;
Expand Down
5 changes: 4 additions & 1 deletion src/modules/user/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Controller } from '@nestjs/common';
import { AuthService } from './auth.service';

@Controller('auth')
export class AuthController {}
export class AuthController {
constructor(private authService: AuthService) {}
}
6 changes: 5 additions & 1 deletion src/modules/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Module } from '@nestjs/common';
import { ExceptionService } from 'src/shared';
import { AuthController, AuthService } from './auth';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from 'src/schemas';

@Module({
imports: [],
imports: [
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
],
providers: [ExceptionService, AuthService],
controllers: [AuthController],
})
Expand Down
3 changes: 2 additions & 1 deletion src/schemas/user/user.schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';
import { Gender } from 'src/enums';
import { Gender, UserRole } from 'src/enums';

export type UserDocument = HydratedDocument<User>;

Expand All @@ -13,6 +13,7 @@ export class User {
@Prop() password: string;
@Prop() address: string;
@Prop() phone: string;
@Prop() role: UserRole;
@Prop() zipcode: string;
@Prop() avatar: string;
@Prop() gender: Gender;
Expand Down

0 comments on commit 8072894

Please sign in to comment.