chore: seeder for city and province
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import { Controller } from "@nestjs/common";
|
||||
|
||||
@Controller("address")
|
||||
export class AddressController {
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { AddressController } from "./address.controller";
|
||||
import { City } from "./entities/city.entity";
|
||||
import { Province } from "./entities/province.entity";
|
||||
import { AddressService } from "./providers/address.service";
|
||||
import { CityRepository } from "./repositories/city.repository";
|
||||
import { ProvinceRepository } from "./repositories/province.repository";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([City, Province])],
|
||||
providers: [AddressService, CityRepository, ProvinceRepository],
|
||||
controllers: [AddressController],
|
||||
})
|
||||
export class AddressModule {}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
import { Province } from "./province.entity";
|
||||
|
||||
@Entity()
|
||||
export class City {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
name: string;
|
||||
|
||||
@ManyToOne(() => Province, (province) => province.cities, { nullable: false })
|
||||
province: Province;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
import { City } from "./city.entity";
|
||||
|
||||
@Entity()
|
||||
export class Province {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
name: string;
|
||||
|
||||
@OneToMany(() => City, (city) => city.province)
|
||||
cities: City[];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class AddressService {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { City } from "../entities/city.entity";
|
||||
|
||||
@Injectable()
|
||||
export class CityRepository extends Repository<City> {
|
||||
constructor(@InjectRepository(City) cityRepository: Repository<City>) {
|
||||
super(cityRepository.target, cityRepository.manager, cityRepository.queryRunner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { Province } from "../entities/province.entity";
|
||||
|
||||
@Injectable()
|
||||
export class ProvinceRepository extends Repository<Province> {
|
||||
constructor(@InjectRepository(Province) provinceRepository: Repository<Province>) {
|
||||
super(provinceRepository.target, provinceRepository.manager, provinceRepository.queryRunner);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Body, Controller, Get, Param, Post, Query } from "@nestjs/common";
|
||||
import { ApiOperation } from "@nestjs/swagger";
|
||||
|
||||
import { ApplyDiscountDto } from "./DTO/apply-discount-invoice.dto";
|
||||
import { CreateInvoiceDto } from "./DTO/create-invoice.dto";
|
||||
import { InvoicesSearchQueryDto, UserInvoicesSearchQueryDto } from "./DTO/invoices-search-query.dto";
|
||||
import { InvoicesService } from "./providers/invoices.service";
|
||||
@@ -48,4 +49,14 @@ export class InvoicesController {
|
||||
getInvoiceById(@Param() paramDto: ParamDto, @UserDec("role") role: RoleEnum, @UserDec("id") userId: string) {
|
||||
return this.invoiceService.getInvoiceById(paramDto.id, role, userId);
|
||||
}
|
||||
|
||||
@Post(":id/apply-discount")
|
||||
async applyDiscount(@Param() paramDto: ParamDto, @Body() applyDiscountDto: ApplyDiscountDto) {
|
||||
return this.invoiceService.applyDiscount(paramDto.id, applyDiscountDto);
|
||||
}
|
||||
|
||||
@Get(":id/final-price")
|
||||
async getFinalPrice(@Param() paramDto: ParamDto) {
|
||||
return this.invoiceService.calculateFinalPrice(paramDto.id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user