feat: adjust data type

This commit is contained in:
Methapon2001 2024-06-26 11:22:48 +07:00
parent e3dac5529f
commit 05dfe42b2e
6 changed files with 2112 additions and 4 deletions

View file

@ -25,6 +25,7 @@
"nodemon": "^3.1.3", "nodemon": "^3.1.3",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"prisma": "^5.12.1", "prisma": "^5.12.1",
"prisma-kysely": "^1.8.0",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"typescript": "^5.4.3" "typescript": "^5.4.3"
}, },
@ -36,7 +37,9 @@
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"express": "^4.19.2", "express": "^4.19.2",
"fast-jwt": "^4.0.0", "fast-jwt": "^4.0.0",
"kysely": "^0.27.3",
"minio": "^7.1.3", "minio": "^7.1.3",
"prisma-extension-kysely": "^2.1.0",
"promise.any": "^2.0.6", "promise.any": "^2.0.6",
"swagger-ui-express": "^5.0.0", "swagger-ui-express": "^5.0.0",
"tsoa": "^6.2.0" "tsoa": "^6.2.0"

1622
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

459
prisma/generated/types.ts Normal file
View file

@ -0,0 +1,459 @@
import type { ColumnType } from "kysely";
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
export const Status = {
CREATED: "CREATED",
ACTIVE: "ACTIVE",
INACTIVE: "INACTIVE"
} as const;
export type Status = (typeof Status)[keyof typeof Status];
export const UserType = {
USER: "USER",
MESSENGER: "MESSENGER",
DELEGATE: "DELEGATE",
AGENCY: "AGENCY"
} as const;
export type UserType = (typeof UserType)[keyof typeof UserType];
export const CustomerType = {
CORP: "CORP",
PERS: "PERS"
} as const;
export type CustomerType = (typeof CustomerType)[keyof typeof CustomerType];
export type Branch = {
id: string;
code: string;
taxNo: string;
name: string;
nameEN: string;
address: string;
addressEN: string;
telephoneNo: string;
provinceId: string | null;
districtId: string | null;
subDistrictId: string | null;
zipCode: string;
email: string;
contactName: string | null;
lineId: string | null;
latitude: string;
longitude: string;
isHeadOffice: Generated<boolean>;
headOfficeId: string | null;
status: Generated<Status>;
statusOrder: Generated<number>;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type BranchContact = {
id: string;
telephoneNo: string;
branchId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type BranchUser = {
id: string;
branchId: string;
userId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type Customer = {
id: string;
code: string;
personName: string;
personNameEN: string | null;
customerType: CustomerType;
customerName: string;
customerNameEN: string;
taxNo: string | null;
status: Generated<Status>;
statusOrder: Generated<number>;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type CustomerBranch = {
id: string;
branchNo: number;
code: string;
legalPersonNo: string;
name: string;
nameEN: string;
customerId: string;
taxNo: string | null;
registerName: string;
registerDate: Timestamp;
authorizedCapital: string;
address: string;
addressEN: string;
provinceId: string | null;
districtId: string | null;
subDistrictId: string | null;
zipCode: string;
email: string;
telephoneNo: string;
employmentOffice: string;
bussinessType: string;
bussinessTypeEN: string;
jobPosition: string;
jobPositionEN: string;
jobDescription: string;
saleEmployee: string;
payDate: Timestamp;
wageRate: number;
status: Generated<Status>;
statusOrder: Generated<number>;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type District = {
id: string;
name: string;
nameEN: string;
provinceId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type Employee = {
id: string;
code: string;
nrcNo: string;
firstName: string;
firstNameEN: string;
lastName: string;
lastNameEN: string;
dateOfBirth: Timestamp;
gender: string;
nationality: string;
address: string | null;
addressEN: string | null;
provinceId: string | null;
districtId: string | null;
subDistrictId: string | null;
zipCode: string;
passportType: string;
passportNumber: string;
passportIssueDate: Timestamp;
passportExpiryDate: Timestamp;
passportIssuingCountry: string;
passportIssuingPlace: string;
previousPassportReference: string | null;
visaType: string | null;
visaNumber: string | null;
visaIssueDate: Timestamp | null;
visaExpiryDate: Timestamp | null;
visaIssuingPlace: string | null;
visaStayUntilDate: Timestamp | null;
tm6Number: string | null;
entryDate: Timestamp | null;
workerStatus: string | null;
customerBranchId: string | null;
status: Generated<Status>;
statusOrder: Generated<number>;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type EmployeeCheckup = {
id: string;
employeeId: string;
checkupResult: string | null;
checkupType: string | null;
provinceId: string | null;
hospitalName: string | null;
remark: string | null;
medicalBenefitScheme: string | null;
insuranceCompany: string | null;
coverageStartDate: Timestamp | null;
coverageExpireDate: Timestamp | null;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type EmployeeOtherInfo = {
id: string;
employeeId: string;
citizenId: string | null;
fatherBirthPlace: string | null;
fatherFirstName: string | null;
fatherLastName: string | null;
motherBirthPlace: string | null;
motherFirstName: string | null;
motherLastName: string | null;
fatherFirstNameEN: string | null;
fatherLastNameEN: string | null;
motherFirstNameEN: string | null;
motherLastNameEN: string | null;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type EmployeeWork = {
id: string;
employeeId: string;
ownerName: string | null;
positionName: string | null;
jobType: string | null;
workplace: string | null;
workPermitNo: string | null;
workPermitIssuDate: Timestamp | null;
workPermitExpireDate: Timestamp | null;
workEndDate: Timestamp | null;
remark: string | null;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type Menu = {
id: string;
caption: string;
captionEN: string;
menuType: string;
url: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
parentId: string | null;
};
export type MenuComponent = {
id: string;
componentId: string;
componentTag: string;
menuId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type Product = {
id: string;
code: string;
name: string;
detail: string;
process: number;
price: number;
agentPrice: number;
serviceCharge: number;
status: Generated<Status>;
statusOrder: Generated<number>;
remark: string | null;
productTypeId: string | null;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type ProductGroup = {
id: string;
code: string;
name: string;
detail: string;
remark: string;
status: Generated<Status>;
statusOrder: Generated<number>;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type ProductType = {
id: string;
code: string;
name: string;
detail: string;
remark: string;
status: Generated<Status>;
statusOrder: Generated<number>;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
productGroupId: string;
};
export type Province = {
id: string;
name: string;
nameEN: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type RoleMenuComponentPermission = {
id: string;
userRole: string;
permission: string;
menuComponentId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type RoleMenuPermission = {
id: string;
userRole: string;
permission: string;
menuId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type RunningNo = {
key: string;
value: number;
};
export type Service = {
id: string;
code: string;
name: string;
detail: string;
attributes: unknown | null;
status: Generated<Status>;
statusOrder: Generated<number>;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type SubDistrict = {
id: string;
name: string;
nameEN: string;
zipCode: string;
districtId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type User = {
id: string;
code: string | null;
firstName: string;
firstNameEN: string;
lastName: string;
lastNameEN: string;
username: string;
gender: string;
address: string;
addressEN: string;
provinceId: string | null;
districtId: string | null;
subDistrictId: string | null;
zipCode: string;
email: string;
telephoneNo: string;
registrationNo: string | null;
startDate: Timestamp | null;
retireDate: Timestamp | null;
checkpoint: string | null;
checkpointEN: string | null;
userType: UserType;
userRole: string;
discountCondition: string | null;
licenseNo: string | null;
licenseIssueDate: Timestamp | null;
licenseExpireDate: Timestamp | null;
sourceNationality: string | null;
importNationality: string | null;
trainingPlace: string | null;
responsibleArea: string | null;
birthDate: Timestamp | null;
status: Generated<Status>;
statusOrder: Generated<number>;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type UserMenuComponentPermission = {
id: string;
userId: string;
menuComponentId: string;
permission: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type UserMenuPermission = {
id: string;
permission: string;
menuId: string;
userId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type Work = {
id: string;
order: number;
name: string;
attributes: unknown | null;
status: Generated<Status>;
statusOrder: Generated<number>;
serviceId: string | null;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type WorkProduct = {
order: number;
workId: string;
productId: string;
createdBy: string | null;
createdAt: Generated<Timestamp>;
updateBy: string | null;
updatedAt: Timestamp;
};
export type DB = {
Branch: Branch;
BranchContact: BranchContact;
BranchUser: BranchUser;
Customer: Customer;
CustomerBranch: CustomerBranch;
District: District;
Employee: Employee;
EmployeeCheckup: EmployeeCheckup;
EmployeeOtherInfo: EmployeeOtherInfo;
EmployeeWork: EmployeeWork;
Menu: Menu;
MenuComponent: MenuComponent;
Product: Product;
ProductGroup: ProductGroup;
ProductType: ProductType;
Province: Province;
RoleMenuComponentPermission: RoleMenuComponentPermission;
RoleMenuPermission: RoleMenuPermission;
RunningNo: RunningNo;
Service: Service;
SubDistrict: SubDistrict;
User: User;
UserMenuComponentPermission: UserMenuComponentPermission;
UserMenuPermission: UserMenuPermission;
Work: Work;
WorkProduct: WorkProduct;
};

View file

@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE "Product" ALTER COLUMN "price" SET DATA TYPE DOUBLE PRECISION,
ALTER COLUMN "agentPrice" SET DATA TYPE DOUBLE PRECISION,
ALTER COLUMN "serviceCharge" SET DATA TYPE DOUBLE PRECISION;

View file

@ -2,6 +2,10 @@ generator client {
provider = "prisma-client-js" provider = "prisma-client-js"
} }
generator kysely {
provider = "prisma-kysely"
}
datasource db { datasource db {
provider = "postgresql" provider = "postgresql"
url = env("DATABASE_URL") url = env("DATABASE_URL")
@ -644,9 +648,9 @@ model Product {
name String name String
detail String detail String
process Int process Int
price Int price Float
agentPrice Int agentPrice Float
serviceCharge Int serviceCharge Float
status Status @default(CREATED) status Status @default(CREATED)
statusOrder Int @default(0) statusOrder Int @default(0)

View file

@ -1,7 +1,23 @@
import { PrismaClient } from "@prisma/client"; import { PrismaClient } from "@prisma/client";
import kyselyExtension from "prisma-extension-kysely";
import type { DB } from "../prisma/generated/types.ts";
import { Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler } from "kysely";
const prisma = new PrismaClient({ const prisma = new PrismaClient({
errorFormat: process.env.NODE_ENV === "production" ? "minimal" : "pretty", errorFormat: process.env.NODE_ENV === "production" ? "minimal" : "pretty",
}); }).$extends(
kyselyExtension({
kysely: (driver) =>
new Kysely<DB>({
dialect: {
createDriver: () => driver,
createAdapter: () => new PostgresAdapter(),
createIntrospector: (db: Kysely<DB>) => new PostgresIntrospector(db),
createQueryCompiler: () => new PostgresQueryCompiler(),
},
plugins: [],
}),
}),
);
export default prisma; export default prisma;