update permission

This commit is contained in:
mamoss 2025-12-07 13:51:01 +07:00
parent b436b67167
commit f814454003
15 changed files with 99587 additions and 83 deletions

View file

@ -102,6 +102,9 @@ import { HR_PERSONAL_EMPTEMP_ADDRESS } from "../entities/mis/HR_PERSONAL_EMPTEMP
import { HR_PERSONAL_EMPTEMP_FAMILY } from "../entities/mis/HR_PERSONAL_EMPTEMP_FAMILY";
import { HR_POSITION_EMPLOYEETEMP } from "../entities/mis/HR_POSITION_EMPLOYEETEMP";
import { positionOfficer } from "../entities/mis/positionOfficer";
import { ProvinceMaster } from "../entities/ProvinceMaster";
import { SubDistrictMaster } from "../entities/SubDistrictMaster";
import { DistrictMaster } from "../entities/DistrictMaster";
@Route("api/v1/org/upload")
@Tags("UPLOAD")
@Security("bearerAuth")
@ -6362,4 +6365,448 @@ export class ImportDataController extends Controller {
}
return new HttpSuccess();
}
}
// /**
// * @summary Update importUpdate for provinces matching JSON
// */
// @Post("updateProvinceImportOld")
// async updateProvinceImportOld() {
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/provinces.json");
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// let num = 0;
// const Fuse = require("fuse.js");
// const fuse = new Fuse(
// provinceJson.map((x: any) => x.name_th),
// {
// includeScore: true,
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
// },
// );
// const provinces = await this.provinceIdRepo.find({ where: { importUpdate: IsNull() } });
// for (const prov of provinces) {
// console.log("11");
// const result = fuse.search(prov.name);
// const repoProvince = AppDataSource.getRepository(ProvinceMaster);
// console.log("1221");
// if (result.length > 0) {
// let foundItem = result[0];
// if (result.length > 1) {
// foundItem = result.filter((x: any) => x.score == 0)[0];
// if (foundItem == null) {
// continue;
// }
// }
// const province = await repoProvince.findOne({
// where: { name_th: foundItem.item },
// });
// if (province == null) {
// console.log(foundItem.item);
// num += 1;
// continue;
// }
// console.log("1441");
// prov.importUpdate = 1;
// prov.refId = province.id;
// prov.name = province.name_th;
// await this.provinceIdRepo.save(prov);
// } else {
// console.log("qqqqq");
// console.log(prov.name);
// console.log(result);
// num += 1;
// }
// }
// console.log("not found province count:", num);
// return new HttpSuccess();
// }
// /**
// * @summary Update importUpdate for districts matching JSON
// */
// @Post("updateDistrictImportOld")
// async updateDistrictImportOld() {
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/tambons.json");
// const districtJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// let num = 0;
// const Fuse = require("fuse.js");
// const districts = await this.districtIdRepo.find({
// relations: ["province"],
// where: { province: { refId: Not(IsNull()) }, importUpdate: IsNull() },
// });
// for (const prov of districts) {
// const fuse = new Fuse(
// districtJson
// .filter((x: any) => x.province_id === prov.province?.refId)
// .map((x: any) => x.name_th),
// {
// includeScore: true,
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
// },
// );
// const result = fuse.search(prov.name);
// const repoDistrict = AppDataSource.getRepository(DistrictMaster);
// if (result.length > 0) {
// let foundItem = result[0];
// if (result.length > 1) {
// foundItem = result.filter((x: any) => x.score == 0)[0];
// if (foundItem == null) {
// continue;
// }
// }
// const district = await repoDistrict.findOne({
// where: { name_th: foundItem.item, province_id: prov.province?.refId },
// });
// if (district == null) {
// num += 1;
// continue;
// }
// prov.importUpdate = 1;
// prov.refId = district.id;
// prov.name = district.name_th;
// await this.districtIdRepo.save(prov);
// } else {
// num += 1;
// }
// }
// console.log("not found district count:", num);
// return new HttpSuccess();
// }
// /**
// * @summary Update importUpdate for subdistricts matching JSON
// */
// @Post("updateSubDistrictImportOld")
// async updateSubDistrictImportOld() {
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/amphures.json");
// const subDistrictJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// let num = 0;
// const Fuse = require("fuse.js");
// const subDistricts = await this.subDistrictIdRepo.find({
// relations: ["district"],
// where: { district: { refId: Not(IsNull()) }, importUpdate: IsNull() },
// });
// for (const prov of subDistricts) {
// const fuse = new Fuse(
// subDistrictJson
// .filter((x: any) => x.district_id === prov.district?.refId)
// .map((x: any) => x.name_th),
// {
// includeScore: true,
// threshold: 0.2, // ยิ่งต่ำยิ่งเข้มงวด
// },
// );
// const result = fuse.search(prov.name);
// const repoSubDistrict = AppDataSource.getRepository(SubDistrictMaster);
// if (result.length > 0) {
// let foundItem = result[0];
// if (result.length > 1) {
// foundItem = result.filter((x: any) => x.score == 0)[0];
// if (foundItem == null) {
// continue;
// }
// }
// const subdistrict = await repoSubDistrict.findOne({
// where: { name_th: foundItem.item, district_id: prov.district?.refId },
// });
// if (subdistrict == null) {
// num += 1;
// continue;
// }
// prov.importUpdate = 1;
// prov.refId = subdistrict.id;
// prov.name = subdistrict.name_th;
// prov.zipCode = subdistrict.zip_code.toString();
// await this.subDistrictIdRepo.save(prov);
// } else {
// num += 1;
// }
// }
// console.log("not found subdistrict count:", num);
// return new HttpSuccess();
// }
// /**
// * @summary Update importUpdate for provinces matching JSON
// */
// @Post("updateProvinceImportFlag")
// async updateProvinceImportFlag() {
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/provinces.json");
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// let num = 0;
// for (const province of provinceJson) {
// const dbProvince = await this.provinceIdRepo.findOne({
// where: {
// name: province.name_th,
// importUpdate: IsNull(),
// },
// });
// if (dbProvince) {
// dbProvince.importUpdate = 1;
// dbProvince.refId = province.id;
// await this.provinceIdRepo.save(dbProvince);
// } else {
// num += 1;
// }
// }
// console.log("not found province count:", num);
// return new HttpSuccess();
// }
// /**
// * @summary Update importUpdate for districts matching JSON
// */
// @Post("updateDistrictImportFlag")
// async updateDistrictImportFlag() {
// const meta = {
// createdUserId: "",
// createdFullName: "system",
// lastUpdateUserId: "",
// lastUpdateFullName: "system",
// createdAt: new Date(),
// lastUpdatedAt: new Date(),
// };
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/tambons.json");
// const tambonJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// let num = 0;
// for (const tambon of tambonJson) {
// const dbDistrict = await this.districtIdRepo.findOne({
// where: {
// name: tambon.name_th,
// province: { refId: Not(tambon.province_id) },
// importUpdate: IsNull(),
// },
// });
// if (dbDistrict) {
// const dbProvince = await this.provinceIdRepo.findOne({
// where: {
// refId: tambon.province_id,
// importUpdate: Not(IsNull()),
// },
// });
// if (dbProvince) {
// const checkOld = await this.districtIdRepo.findOne({
// where: {
// name: tambon.name_th,
// provinceId: dbProvince.id,
// },
// });
// if (!checkOld) {
// let districtId = new District();
// Object.assign(districtId, {
// ...meta,
// name: tambon.name_th,
// provinceId: dbProvince.id,
// importUpdate: 2,
// refId: tambon.id,
// });
// await this.districtIdRepo.save(districtId);
// num += 1;
// }
// }
// }
// }
// console.log("not found province count:", num);
// return new HttpSuccess();
// }
// /**
// * @summary Update importUpdate for subdistricts matching JSON
// */
// @Post("updateSubDistrictImportFlag")
// async updateSubDistrictImportFlag() {
// const meta = {
// createdUserId: "",
// createdFullName: "system",
// lastUpdateUserId: "",
// lastUpdateFullName: "system",
// createdAt: new Date(),
// lastUpdatedAt: new Date(),
// };
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/amphures.json");
// const amphureJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// let num = 0;
// for (const amphure of amphureJson) {
// const dbSubDistrict = await this.subDistrictIdRepo.findOne({
// where: {
// name: amphure.name_th,
// district: { refId: Not(amphure.district_id) },
// importUpdate: IsNull(),
// },
// });
// if (dbSubDistrict) {
// const dbDistrict = await this.districtIdRepo.findOne({
// where: {
// refId: amphure.district_id,
// importUpdate: Not(IsNull()),
// },
// });
// if (dbDistrict) {
// const checkOld = await this.subDistrictIdRepo.findOne({
// where: {
// name: amphure.name_th,
// districtId: dbDistrict.id,
// },
// });
// if (!checkOld) {
// let districtId = new District();
// Object.assign(districtId, {
// ...meta,
// name: amphure.name_th,
// districtId: dbDistrict.id,
// zipCode: amphure.zip_code,
// importUpdate: 2,
// refId: amphure.id,
// });
// await this.subDistrictIdRepo.save(districtId);
// num += 1;
// }
// }
// }
// }
// console.log("not found province count:", num);
// return new HttpSuccess();
// }
// /**
// * @summary ตรวจสอบ district ใน profile ว่าตรงกับ tambons.json หรือไม่
// */
// @Post("checkProfileDistrictMismatch")
// async checkProfileDistrictMismatch() {
// const mismatches = [];
// const profiles = await this.profileRepo.find({
// relations: ["registrationProvince", "registrationDistrict", "registrationSubDistrict"],
// where: {
// registrationProvince: Not(IsNull()),
// },
// });
// for (const profile of profiles) {
// console.log("profile count:", profiles.indexOf(profile) + 1);
// console.log("mismatches count:", mismatches.length);
// // if (mismatches.length >= 10) {
// // break;
// // }
// const repoProvince = AppDataSource.getRepository(ProvinceMaster);
// const repoDistrict = AppDataSource.getRepository(DistrictMaster);
// const repoSubDistrict = AppDataSource.getRepository(SubDistrictMaster);
// const registrationProvince = profile.registrationProvince?.name;
// const registrationDistrict = profile.registrationDistrict?.name;
// const registrationSubDistrict = profile.registrationSubDistrict?.name;
// const province = await repoProvince.findOne({
// where: { name_th: registrationProvince },
// });
// if (province == null) {
// mismatches.push({ profileId: profile.id });
// continue;
// }
// const district = await repoDistrict.findOne({
// where: { name_th: registrationDistrict, province_id: province.id },
// });
// if (district == null) {
// mismatches.push({ profileId: profile.id });
// continue;
// }
// const subdistrict = await repoSubDistrict.findOne({
// where: { name_th: registrationSubDistrict, district_id: district.id },
// });
// if (subdistrict == null) {
// mismatches.push({ profileId: profile.id });
// continue;
// }
// }
// return mismatches.map((x) => x.profileId);
// }
// /**
// * @summary Import provinces.json into ProvinceMaster table
// */
// @Post("importProvinceMaster")
// async importProvinceMaster() {
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/provinces.json");
// const provinceJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// const repo = AppDataSource.getRepository(ProvinceMaster);
// let imported = [];
// for (const prov of provinceJson) {
// const newProv = repo.create({
// id: prov.id,
// name_th: prov.name_th,
// name_en: prov.name_en,
// geography_id: prov.geography_id,
// created_at: prov.created_at,
// updated_at: prov.updated_at,
// });
// await repo.save(newProv);
// imported.push(newProv);
// }
// return imported;
// }
// /**
// * @summary Import tambons.json into DistrictMaster table
// */
// @Post("importDistrictMaster")
// async importDistrictMaster() {
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/tambons.json");
// const tambonJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// const repo = AppDataSource.getRepository(DistrictMaster);
// let imported = [];
// for (const tambon of tambonJson) {
// const newSub = repo.create({
// id: tambon.id,
// name_th: tambon.name_th,
// name_en: tambon.name_en,
// province_id: tambon.province_id,
// created_at: tambon.created_at,
// updated_at: tambon.updated_at,
// });
// await repo.save(newSub);
// imported.push(newSub);
// }
// return imported;
// }
// /**
// * @summary Import amphures.json into SubDistrictMaster table
// */
// @Post("importSubDistrictMaster")
// async importSubDistrictMaster() {
// const fs = require("fs");
// const path = require("path");
// const filePath = path.join(__dirname, "../data/amphures.json");
// const amphureJson = JSON.parse(fs.readFileSync(filePath, "utf8"));
// const repo = AppDataSource.getRepository(SubDistrictMaster);
// // Prepare all entities first
// const entities = amphureJson.map((amphure: any) =>
// repo.create({
// id: amphure.id,
// zip_code: amphure.zip_code,
// name_th: amphure.name_th,
// name_en: amphure.name_en,
// district_id: amphure.district_id,
// lat: amphure.lat,
// long: amphure.long,
// created_at: amphure.created_at,
// updated_at: amphure.updated_at,
// }),
// );
// // Bulk insert for performance
// await repo.save(entities);
// return entities;
// }
// }

View file

@ -6128,7 +6128,7 @@ export class OrganizationController extends Controller {
if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
let _data:any = {
let _data: any = {
root: null,
child1: null,
child2: null,
@ -6141,7 +6141,7 @@ export class OrganizationController extends Controller {
) {
_data = await new permission().PermissionOrgList(request, system.trim().toUpperCase());
}
const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
relations: ["permissionProfiles", "current_holders"],
@ -6150,32 +6150,32 @@ export class OrganizationController extends Controller {
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ");
}
let _privilege = await new permission().PermissionOrgList(request, system);
const attrOwnership = _privilege.root === null ? true : false;
if (orgRevision.orgRevisionIsDraft && !orgRevision.orgRevisionIsCurrent && !attrOwnership) {
if(Array.isArray(profile.permissionProfiles) && profile.permissionProfiles.length > 0){
if (Array.isArray(profile.permissionProfiles) && profile.permissionProfiles.length > 0) {
_data.root = profile.permissionProfiles.map((x) => x.orgRootId);
}else{
} else {
return new HttpSuccess({ remark: "", data: [] });
}
}
}
// กำหนดการเข้าถึงข้อมูลตามสถานะและสิทธิ์
const isCurrentActive = !orgRevision.orgRevisionIsDraft && orgRevision.orgRevisionIsCurrent;
if (isCurrentActive) {
if(_privilege.privilege !== "OWNER"){
if(_privilege.privilege == "NORMAL"){
const holder = profile.current_holders.find(x => x.orgRevisionId === id);
if (_privilege.privilege !== "OWNER") {
if (_privilege.privilege == "NORMAL") {
const holder = profile.current_holders.find((x) => x.orgRevisionId === id);
if (!holder) return;
_data.root = [holder.orgRootId];
_data.child1 = [holder.orgChild1Id];
_data.child2 = [holder.orgChild2Id];
_data.child3 = [holder.orgChild3Id];
_data.child4 = [holder.orgChild4Id];
}else if(_privilege.privilege == "CHILD"){
const holder = profile.current_holders.find(x => x.orgRevisionId === id);
} else if (_privilege.privilege == "CHILD") {
const holder = profile.current_holders.find((x) => x.orgRevisionId === id);
if (!holder) return;
_data.root = [holder.orgRootId];
if (_privilege.root && _privilege.child1 === null) {
@ -6190,7 +6190,7 @@ export class OrganizationController extends Controller {
_data.child3 = [holder.orgChild3Id];
_data.child4 = [holder.orgChild4Id];
}
}else{
} else {
_data.root = [profile.current_holders.find((x) => x.orgRevisionId === id)?.orgRootId];
}
} else {
@ -6242,7 +6242,7 @@ export class OrganizationController extends Controller {
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? `orgChild1.id IN (:...node)`
: `orgChild1.id is null`
: `orgChild1.id is ${_data.privilege == "PARENT" ? "not null" : "null"}`
: "1=1",
{
node: _data.child1,

View file

@ -735,7 +735,7 @@ export class PermissionController extends Controller {
} else if (privilege == "PARENT") {
data = {
root: [x.orgRootId],
child1: null,
child1: [null],
child2: null,
child3: null,
child4: null,

89414
src/data/amphures.json Normal file

File diff suppressed because it is too large Load diff

695
src/data/provinces.json Normal file
View file

@ -0,0 +1,695 @@
[
{
"id": 1,
"name_th": "กรุงเทพมหานคร",
"name_en": "Bangkok",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 2,
"name_th": "สมุทรปราการ",
"name_en": "Samut Prakan",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 3,
"name_th": "นนทบุรี",
"name_en": "Nonthaburi",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 4,
"name_th": "ปทุมธานี",
"name_en": "Pathum Thani",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 5,
"name_th": "พระนครศรีอยุธยา",
"name_en": "Phra Nakhon Si Ayutthaya",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 6,
"name_th": "อ่างทอง",
"name_en": "Ang Thong",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 7,
"name_th": "ลพบุรี",
"name_en": "Lopburi",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 8,
"name_th": "สิงห์บุรี",
"name_en": "Sing Buri",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 9,
"name_th": "ชัยนาท",
"name_en": "Chai Nat",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 10,
"name_th": "สระบุรี",
"name_en": "Saraburi",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 11,
"name_th": "ชลบุรี",
"name_en": "Chon Buri",
"geography_id": 5,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 12,
"name_th": "ระยอง",
"name_en": "Rayong",
"geography_id": 5,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 13,
"name_th": "จันทบุรี",
"name_en": "Chanthaburi",
"geography_id": 5,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 14,
"name_th": "ตราด",
"name_en": "Trat",
"geography_id": 5,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 15,
"name_th": "ฉะเชิงเทรา",
"name_en": "Chachoengsao",
"geography_id": 5,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 16,
"name_th": "ปราจีนบุรี",
"name_en": "Prachin Buri",
"geography_id": 5,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 17,
"name_th": "นครนายก",
"name_en": "Nakhon Nayok",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 18,
"name_th": "สระแก้ว",
"name_en": "Sa Kaeo",
"geography_id": 5,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 19,
"name_th": "นครราชสีมา",
"name_en": "Nakhon Ratchasima",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 20,
"name_th": "บุรีรัมย์",
"name_en": "Buri Ram",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 21,
"name_th": "สุรินทร์",
"name_en": "Surin",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 22,
"name_th": "ศรีสะเกษ",
"name_en": "Si Sa Ket",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 23,
"name_th": "อุบลราชธานี",
"name_en": "Ubon Ratchathani",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 24,
"name_th": "ยโสธร",
"name_en": "Yasothon",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 25,
"name_th": "ชัยภูมิ",
"name_en": "Chaiyaphum",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 26,
"name_th": "อำนาจเจริญ",
"name_en": "Amnat Charoen",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 27,
"name_th": "หนองบัวลำภู",
"name_en": "Nong Bua Lam Phu",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 28,
"name_th": "ขอนแก่น",
"name_en": "Khon Kaen",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 29,
"name_th": "อุดรธานี",
"name_en": "Udon Thani",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 30,
"name_th": "เลย",
"name_en": "Loei",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 31,
"name_th": "หนองคาย",
"name_en": "Nong Khai",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 32,
"name_th": "มหาสารคาม",
"name_en": "Maha Sarakham",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 33,
"name_th": "ร้อยเอ็ด",
"name_en": "Roi Et",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 34,
"name_th": "กาฬสินธุ์",
"name_en": "Kalasin",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 35,
"name_th": "สกลนคร",
"name_en": "Sakon Nakhon",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 36,
"name_th": "นครพนม",
"name_en": "Nakhon Phanom",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 37,
"name_th": "มุกดาหาร",
"name_en": "Mukdahan",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 38,
"name_th": "เชียงใหม่",
"name_en": "Chiang Mai",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 39,
"name_th": "ลำพูน",
"name_en": "Lamphun",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 40,
"name_th": "ลำปาง",
"name_en": "Lampang",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 41,
"name_th": "อุตรดิตถ์",
"name_en": "Uttaradit",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 42,
"name_th": "แพร่",
"name_en": "Phrae",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 43,
"name_th": "น่าน",
"name_en": "Nan",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 44,
"name_th": "พะเยา",
"name_en": "Phayao",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 45,
"name_th": "เชียงราย",
"name_en": "Chiang Rai",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 46,
"name_th": "แม่ฮ่องสอน",
"name_en": "Mae Hong Son",
"geography_id": 1,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 47,
"name_th": "นครสวรรค์",
"name_en": "Nakhon Sawan",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 48,
"name_th": "อุทัยธานี",
"name_en": "Uthai Thani",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 49,
"name_th": "กำแพงเพชร",
"name_en": "Kamphaeng Phet",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 50,
"name_th": "ตาก",
"name_en": "Tak",
"geography_id": 4,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 51,
"name_th": "สุโขทัย",
"name_en": "Sukhothai",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 52,
"name_th": "พิษณุโลก",
"name_en": "Phitsanulok",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 53,
"name_th": "พิจิตร",
"name_en": "Phichit",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 54,
"name_th": "เพชรบูรณ์",
"name_en": "Phetchabun",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 55,
"name_th": "ราชบุรี",
"name_en": "Ratchaburi",
"geography_id": 4,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 56,
"name_th": "กาญจนบุรี",
"name_en": "Kanchanaburi",
"geography_id": 4,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 57,
"name_th": "สุพรรณบุรี",
"name_en": "Suphan Buri",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 58,
"name_th": "นครปฐม",
"name_en": "Nakhon Pathom",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 59,
"name_th": "สมุทรสาคร",
"name_en": "Samut Sakhon",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 60,
"name_th": "สมุทรสงคราม",
"name_en": "Samut Songkhram",
"geography_id": 2,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 61,
"name_th": "เพชรบุรี",
"name_en": "Phetchaburi",
"geography_id": 4,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 62,
"name_th": "ประจวบคีรีขันธ์",
"name_en": "Prachuap Khiri Khan",
"geography_id": 4,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 63,
"name_th": "นครศรีธรรมราช",
"name_en": "Nakhon Si Thammarat",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 64,
"name_th": "กระบี่",
"name_en": "Krabi",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 65,
"name_th": "พังงา",
"name_en": "Phangnga",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 66,
"name_th": "ภูเก็ต",
"name_en": "Phuket",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 67,
"name_th": "สุราษฎร์ธานี",
"name_en": "Surat Thani",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 68,
"name_th": "ระนอง",
"name_en": "Ranong",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 69,
"name_th": "ชุมพร",
"name_en": "Chumphon",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 70,
"name_th": "สงขลา",
"name_en": "Songkhla",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 71,
"name_th": "สตูล",
"name_en": "Satun",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 72,
"name_th": "ตรัง",
"name_en": "Trang",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 73,
"name_th": "พัทลุง",
"name_en": "Phatthalung",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 74,
"name_th": "ปัตตานี",
"name_en": "Pattani",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 75,
"name_th": "ยะลา",
"name_en": "Yala",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 76,
"name_th": "นราธิวาส",
"name_en": "Narathiwat",
"geography_id": 6,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
},
{
"id": 77,
"name_th": "บึงกาฬ",
"name_en": "Bueng Kan",
"geography_id": 3,
"created_at": "2019-08-09T03:33:09.000+07:00",
"updated_at": "2025-09-20T06:31:26.000+07:00",
"deleted_at": null
}
]

8372
src/data/tambons.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -19,6 +19,18 @@ export class District extends EntityBase {
})
provinceId: string;
// @Column({
// comment: "mark",
// default: null,
// })
// importUpdate: number;
// @Column({
// comment: "refId",
// default: null,
// })
// refId: number;
@ManyToOne(() => Province, (province) => province.districts)
@JoinColumn({ name: "provinceId" })
province: Province;

View file

@ -0,0 +1,22 @@
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
@Entity("district_master")
export class DistrictMaster {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 255 })
name_th: string;
@Column({ length: 255 })
name_en: string;
@Column()
province_id: number;
@Column({ nullable: true })
created_at: string;
@Column({ nullable: true })
updated_at: string;
}

View file

@ -12,6 +12,18 @@ export class Province extends EntityBase {
})
name: string;
// @Column({
// comment: "mark",
// default: null,
// })
// importUpdate: number;
// @Column({
// comment: "refId",
// default: null,
// })
// refId: number;
@OneToMany(() => District, (district) => district.province)
districts: District[];

View file

@ -0,0 +1,22 @@
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
@Entity("province_master")
export class ProvinceMaster {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 255 })
name_th: string;
@Column({ length: 255 })
name_en: string;
@Column()
geography_id: number;
@Column({ nullable: true })
created_at: string;
@Column({ nullable: true })
updated_at: string;
}

View file

@ -26,6 +26,18 @@ export class SubDistrict extends EntityBase {
})
districtId: string;
// @Column({
// comment: "mark",
// default: null,
// })
// importUpdate: number;
// @Column({
// comment: "refId",
// default: null,
// })
// refId: number;
@ManyToOne(() => District, (district) => district.subDistricts)
@JoinColumn({ name: "districtId" })
district: District;

View file

@ -0,0 +1,31 @@
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
@Entity("subdistrict_master")
export class SubDistrictMaster {
@PrimaryGeneratedColumn()
id: number;
@Column()
zip_code: number;
@Column({ length: 255 })
name_th: string;
@Column({ length: 255 })
name_en: string;
@Column()
district_id: number;
@Column({ type: "float", nullable: true })
lat: number | null;
@Column({ type: "float", nullable: true })
long: number | null;
@Column({ type: "timestamp", nullable: true })
created_at: string;
@Column({ type: "timestamp", nullable: true })
updated_at: string;
}

View file

@ -97,7 +97,7 @@ class CheckAuth {
} else if (privilege == "PARENT") {
data = {
root: [x.orgRootId],
child1: null,
child1: [null],
child2: null,
child3: null,
child4: null,