Create product module and model

master
nicekid1 2 months ago
parent 238cd06920
commit 44b3017ce4
  1. 2
      src/app.module.ts
  2. 22
      src/products/entities/product.entity.ts
  3. 8
      src/products/products.controller.ts
  4. 9
      src/products/products.module.ts
  5. 6
      src/products/products.service.ts
  6. 23
      src/users/users.controller.ts

@ -5,6 +5,7 @@ import { ConfigModule } from "@nestjs/config";
import { SequelizeModule } from "@nestjs/sequelize";
import { databaseConfig } from "./config/database.config";
import { UsersModule } from './users/users.module';
import { ProductsModule } from './products/products.module';
@Module({
imports: [
@ -13,6 +14,7 @@ import { UsersModule } from './users/users.module';
}),
SequelizeModule.forRoot(databaseConfig),
UsersModule,
ProductsModule,
],
controllers: [AppController],
providers: [AppService],

@ -0,0 +1,22 @@
import { Model, Table, Column, DataType } from "sequelize-typescript";
@Table
export class Product extends Model<Product> {
@Column({
type: DataType.STRING,
allowNull: false,
})
name: string;
@Column({
type: DataType.STRING,
allowNull: false,
})
description: string;
@Column({
type: DataType.DECIMAL(10, 2),
allowNull: false,
})
price: number;
}

@ -0,0 +1,8 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { ProductsService } from './products.service';
@Controller('products')
export class ProductsController {
constructor(private readonly productsService: ProductsService) {}
}

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ProductsService } from './products.service';
import { ProductsController } from './products.controller';
@Module({
controllers: [ProductsController],
providers: [ProductsService],
})
export class ProductsModule {}

@ -0,0 +1,6 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class ProductsService {
}

@ -1,25 +1,20 @@
import { Controller, Post, Body, Res } from '@nestjs/common';
import { UsersService } from './users.service';
import { Response } from 'express';
import { Controller, Post, Body, Res, UseGuards, Get } from "@nestjs/common";
import { UsersService } from "./users.service";
import { Response } from "express";
import { JwtAuthGuard } from "src/guard/auth.guard";
@Controller('users')
@Controller("users")
export class UsersController {
constructor(private readonly usersService: UsersService) {}
@Post('register')
async register(
@Body() body: { email: string; password: string },
@Res() res: Response
): Promise<Response> {
@Post("register")
async register(@Body() body: { email: string; password: string }, @Res() res: Response): Promise<Response> {
const { email, password } = body;
return this.usersService.register(email, password, res);
}
@Post('login')
async login(
@Body() body: { email: string; password: string },
@Res() res: Response
): Promise<Response> {
@Post("login")
async login(@Body() body: { email: string; password: string }, @Res() res: Response): Promise<Response> {
const { email, password } = body;
return this.usersService.login(email, password, res);
}

Loading…
Cancel
Save