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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user