feat: add province, district, sub-district endpoint
This commit is contained in:
parent
bee7c0bfa5
commit
d58046502c
1 changed files with 56 additions and 0 deletions
56
src/controllers/address-controller.ts
Normal file
56
src/controllers/address-controller.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { Controller, Get, Path, Route, Tags } from "tsoa";
|
||||
import prisma from "../db";
|
||||
|
||||
@Route("api/address")
|
||||
@Tags("Address")
|
||||
export class AddressController extends Controller {
|
||||
@Get("province")
|
||||
async getProvince() {
|
||||
return await prisma.province.findMany();
|
||||
}
|
||||
|
||||
@Get("province/{provinceId}")
|
||||
async getProvinceById(@Path() provinceId: string) {
|
||||
return await prisma.province.findFirst({
|
||||
where: { id: provinceId },
|
||||
});
|
||||
}
|
||||
|
||||
@Get("province/{provinceId}/district")
|
||||
async getDistrictOfProvince(@Path() provinceId: string) {
|
||||
return await prisma.district.findMany({
|
||||
where: { provinceId },
|
||||
});
|
||||
}
|
||||
|
||||
@Get("district")
|
||||
async getDistrict() {
|
||||
return await prisma.district.findMany();
|
||||
}
|
||||
|
||||
@Get("district/{districtId}")
|
||||
async getDistrictOfId(@Path() districtId: string) {
|
||||
return await prisma.province.findFirst({
|
||||
where: { id: districtId },
|
||||
});
|
||||
}
|
||||
|
||||
@Get("district/{districtId}/sub-district")
|
||||
async getSubDistrictOfDistrict(@Path() districtId: string) {
|
||||
return await prisma.subDistrict.findMany({
|
||||
where: { districtId },
|
||||
});
|
||||
}
|
||||
|
||||
@Get("sub-district")
|
||||
async getSubDistrict() {
|
||||
return await prisma.subDistrict.findMany();
|
||||
}
|
||||
|
||||
@Get("sub-district/{subDistrictId}")
|
||||
async getSubDistrictOfId(@Path() subDistrictId: string) {
|
||||
return await prisma.subDistrict.findFirst({
|
||||
where: { id: subDistrictId },
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue