Compare commits

..

No commits in common. 'ad738f2c61b82134c084bfeda85830938267bae8' and 'be0f01bc1a5d9991804318804ec072a18902998a' have entirely different histories.

  1. 17
      src/admin/admin.controller.ts
  2. 12
      src/admin/admin.module.ts
  3. 40
      src/admin/admin.service.ts
  4. 12
      src/admin/entities/admin.entity.ts
  5. 2
      src/app.module.ts

@ -1,17 +0,0 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { AdminService } from './admin.service';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import { Admin } from './entities/admin.entity';
import * as bcrypt from 'bcrypt';
import { JwtService } from '@nestjs/jwt';
@Controller('admin')
export class AdminController {
constructor(private readonly adminService: AdminService) {}
@Post('register')
async register(@Body() body:{email: string, password: string}):Promise<Admin>{
const {email, password} = body
return this.adminService.register(email, password);
}
}

@ -1,12 +0,0 @@
import { Module } from '@nestjs/common';
import { AdminService } from './admin.service';
import { AdminController } from './admin.controller';
import { SequelizeModule } from '@nestjs/sequelize';
import { Admin } from './entities/admin.entity';
@Module({
imports:[SequelizeModule.forFeature([Admin])],
controllers: [AdminController],
providers: [AdminService],
})
export class AdminModule {}

@ -1,40 +0,0 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import { Admin } from './entities/admin.entity';
@Injectable()
export class AdminService {
constructor(@InjectModel(Admin) private readonly adminModel: typeof Admin){}
async register(email: string, password: string): Promise<Admin> {
try {
if (!email) {
throw new HttpException('Email should be entered.', HttpStatus.BAD_REQUEST);
}
if (!password) {
throw new HttpException('Password should be entered.', HttpStatus.BAD_REQUEST);
}
const existingAdmin = await this.adminModel.findOne({ where: { email } });
if (existingAdmin) {
throw new HttpException('Email is already registered.', HttpStatus.CONFLICT);
}
const admin = await this.adminModel.create({
email,
password,
role: 'admin',
});
return admin;
} catch (error) {
if (error instanceof HttpException) {
throw error;
}
throw new HttpException(
'An error occurred during registration.',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}

@ -1,12 +0,0 @@
import { Model, Table, Column } from "sequelize-typescript";
@Table
export class Admin extends Model<Admin> {
@Column
email: string;
@Column
password: string;
@Column
role: string;
}

@ -9,7 +9,6 @@ import { ProductsModule } from './products/products.module';
import { CartModule } from './cart/cart.module'; import { CartModule } from './cart/cart.module';
import { WalletModule } from './wallet/wallet.module'; import { WalletModule } from './wallet/wallet.module';
import { InvoiceModule } from './invoice/invoice.module'; import { InvoiceModule } from './invoice/invoice.module';
import { AdminModule } from './admin/admin.module';
@Module({ @Module({
imports: [ imports: [
@ -22,7 +21,6 @@ import { AdminModule } from './admin/admin.module';
CartModule, CartModule,
WalletModule, WalletModule,
InvoiceModule, InvoiceModule,
AdminModule,
], ],
controllers: [AppController], controllers: [AppController],
providers: [AppService], providers: [AppService],

Loading…
Cancel
Save