Merge branch 'refactor/db' into dev

This commit is contained in:
Methapon2001 2024-04-05 08:53:17 +07:00
commit e3de7ed8e9
6 changed files with 82 additions and 65 deletions

View file

@ -4,7 +4,7 @@ CREATE TYPE "Status" AS ENUM ('CREATED', 'USED');
-- CreateTable -- CreateTable
CREATE TABLE "Province" ( CREATE TABLE "Province" (
"id" TEXT NOT NULL, "id" TEXT NOT NULL,
"nameTH" TEXT NOT NULL, "name" TEXT NOT NULL,
"nameEN" TEXT NOT NULL, "nameEN" TEXT NOT NULL,
"createdBy" TEXT, "createdBy" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
@ -17,7 +17,7 @@ CREATE TABLE "Province" (
-- CreateTable -- CreateTable
CREATE TABLE "District" ( CREATE TABLE "District" (
"id" TEXT NOT NULL, "id" TEXT NOT NULL,
"nameTH" TEXT NOT NULL, "name" TEXT NOT NULL,
"nameEN" TEXT NOT NULL, "nameEN" TEXT NOT NULL,
"provinceId" TEXT NOT NULL, "provinceId" TEXT NOT NULL,
"createdBy" TEXT, "createdBy" TEXT,
@ -31,7 +31,7 @@ CREATE TABLE "District" (
-- CreateTable -- CreateTable
CREATE TABLE "SubDistrict" ( CREATE TABLE "SubDistrict" (
"id" TEXT NOT NULL, "id" TEXT NOT NULL,
"nameTH" TEXT NOT NULL, "name" TEXT NOT NULL,
"nameEN" TEXT NOT NULL, "nameEN" TEXT NOT NULL,
"zipCode" TEXT NOT NULL, "zipCode" TEXT NOT NULL,
"districtId" TEXT NOT NULL, "districtId" TEXT NOT NULL,
@ -48,9 +48,9 @@ CREATE TABLE "Branch" (
"id" TEXT NOT NULL, "id" TEXT NOT NULL,
"code" TEXT NOT NULL, "code" TEXT NOT NULL,
"taxNo" TEXT NOT NULL, "taxNo" TEXT NOT NULL,
"nameTH" TEXT NOT NULL, "name" TEXT NOT NULL,
"nameEN" TEXT NOT NULL, "nameEN" TEXT NOT NULL,
"addressTH" TEXT NOT NULL, "address" TEXT NOT NULL,
"addressEN" TEXT NOT NULL, "addressEN" TEXT NOT NULL,
"provinceId" TEXT, "provinceId" TEXT,
"districtId" TEXT, "districtId" TEXT,
@ -103,11 +103,11 @@ CREATE TABLE "User" (
"id" TEXT NOT NULL, "id" TEXT NOT NULL,
"keycloakId" TEXT NOT NULL, "keycloakId" TEXT NOT NULL,
"code" TEXT NOT NULL, "code" TEXT NOT NULL,
"firstNameTH" TEXT NOT NULL, "firstName" TEXT NOT NULL,
"firstNameEN" TEXT NOT NULL, "firstNameEN" TEXT NOT NULL,
"lastNameTH" TEXT NOT NULL, "lastName" TEXT NOT NULL,
"lastNameEN" TEXT NOT NULL, "lastNameEN" TEXT NOT NULL,
"addressTH" TEXT NOT NULL, "address" TEXT NOT NULL,
"addressEN" TEXT NOT NULL, "addressEN" TEXT NOT NULL,
"provinceId" TEXT, "provinceId" TEXT,
"districtId" TEXT, "districtId" TEXT,
@ -141,7 +141,7 @@ CREATE TABLE "Customer" (
"id" TEXT NOT NULL, "id" TEXT NOT NULL,
"code" TEXT NOT NULL, "code" TEXT NOT NULL,
"customerType" TEXT NOT NULL, "customerType" TEXT NOT NULL,
"customerNameTH" TEXT NOT NULL, "customerName" TEXT NOT NULL,
"customerNameEN" TEXT NOT NULL, "customerNameEN" TEXT NOT NULL,
"imageUrl" TEXT, "imageUrl" TEXT,
"status" "Status" NOT NULL DEFAULT 'CREATED', "status" "Status" NOT NULL DEFAULT 'CREATED',
@ -158,7 +158,7 @@ CREATE TABLE "CustomerBranch" (
"id" TEXT NOT NULL, "id" TEXT NOT NULL,
"branchNo" TEXT NOT NULL, "branchNo" TEXT NOT NULL,
"legalPersonNo" TEXT NOT NULL, "legalPersonNo" TEXT NOT NULL,
"nameTH" TEXT NOT NULL, "name" TEXT NOT NULL,
"nameEN" TEXT NOT NULL, "nameEN" TEXT NOT NULL,
"customerId" TEXT NOT NULL, "customerId" TEXT NOT NULL,
"taxNo" TEXT NOT NULL, "taxNo" TEXT NOT NULL,
@ -186,12 +186,12 @@ CREATE TABLE "CustomerBranch" (
CREATE TABLE "Employee" ( CREATE TABLE "Employee" (
"id" TEXT NOT NULL, "id" TEXT NOT NULL,
"code" TEXT NOT NULL, "code" TEXT NOT NULL,
"fullNameTH" TEXT NOT NULL, "fullName" TEXT NOT NULL,
"fullNameEN" TEXT NOT NULL, "fullNameEN" TEXT NOT NULL,
"dateOfBirth" TIMESTAMP(3) NOT NULL, "dateOfBirth" TIMESTAMP(3) NOT NULL,
"gender" TEXT NOT NULL, "gender" TEXT NOT NULL,
"nationality" TEXT NOT NULL, "nationality" TEXT NOT NULL,
"addressTH" TEXT NOT NULL, "address" TEXT NOT NULL,
"addressEN" TEXT NOT NULL, "addressEN" TEXT NOT NULL,
"provinceId" TEXT, "provinceId" TEXT,
"districtId" TEXT, "districtId" TEXT,

View file

@ -0,0 +1,11 @@
-- AlterTable
ALTER TABLE "User" ALTER COLUMN "registrationNo" DROP NOT NULL,
ALTER COLUMN "startDate" DROP NOT NULL,
ALTER COLUMN "retireDate" DROP NOT NULL,
ALTER COLUMN "discountCondition" DROP NOT NULL,
ALTER COLUMN "licenseNo" DROP NOT NULL,
ALTER COLUMN "licenseIssueDate" DROP NOT NULL,
ALTER COLUMN "licenseExpireDate" DROP NOT NULL,
ALTER COLUMN "sourceNationality" DROP NOT NULL,
ALTER COLUMN "importNationality" DROP NOT NULL,
ALTER COLUMN "trainingPlace" DROP NOT NULL;

View file

@ -9,7 +9,7 @@ datasource db {
model Province { model Province {
id String @id @default(uuid()) id String @id @default(uuid())
nameTH String name String
nameEN String nameEN String
createdBy String? createdBy String?
@ -27,7 +27,7 @@ model Province {
model District { model District {
id String @id @default(uuid()) id String @id @default(uuid())
nameTH String name String
nameEN String nameEN String
provinceId String provinceId String
@ -47,7 +47,7 @@ model District {
model SubDistrict { model SubDistrict {
id String @id @default(uuid()) id String @id @default(uuid())
nameTH String name String
nameEN String nameEN String
zipCode String zipCode String
@ -74,9 +74,9 @@ model Branch {
id String @id @default(uuid()) id String @id @default(uuid())
code String @default(uuid()) code String @default(uuid())
taxNo String taxNo String
nameTH String name String
nameEN String nameEN String
addressTH String address String
addressEN String addressEN String
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
@ -148,12 +148,12 @@ model User {
keycloakId String keycloakId String
code String @default(uuid()) code String @default(uuid())
firstNameTH String firstName String
firstNameEN String firstNameEN String
lastNameTH String lastName String
lastNameEN String lastNameEN String
addressTH String address String
addressEN String addressEN String
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
@ -170,24 +170,24 @@ model User {
email String email String
telephoneNo String telephoneNo String
registrationNo String registrationNo String?
startDate DateTime startDate DateTime?
retireDate DateTime retireDate DateTime?
userType String userType String
userRole String userRole String
discountCondition String discountCondition String?
licenseNo String licenseNo String?
licenseIssueDate DateTime licenseIssueDate DateTime?
licenseExpireDate DateTime licenseExpireDate DateTime?
sourceNationality String sourceNationality String?
importNationality String importNationality String?
trainingPlace String trainingPlace String?
status Status @default(CREATED) status Status @default(CREATED)
@ -203,7 +203,7 @@ model Customer {
id String @id @default(uuid()) id String @id @default(uuid())
code String code String
customerType String customerType String
customerNameTH String customerName String
customerNameEN String customerNameEN String
imageUrl String? imageUrl String?
@ -222,7 +222,7 @@ model CustomerBranch {
branchNo String branchNo String
legalPersonNo String legalPersonNo String
nameTH String name String
nameEN String nameEN String
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade) customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
@ -233,6 +233,7 @@ model CustomerBranch {
registerDate DateTime registerDate DateTime
authorizedCapital String authorizedCapital String
address String
addressEN String addressEN String
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
@ -252,6 +253,8 @@ model CustomerBranch {
latitude String latitude String
longitude String longitude String
status Status @default(CREATED)
createdBy String? createdBy String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updateBy String? updateBy String?
@ -264,13 +267,17 @@ model Employee {
id String @id @default(uuid()) id String @id @default(uuid())
code String code String
fullNameTH String nrcNo String
fullNameEN String firstName String
firstNameEN String
lastName String
lastNameEN String
dateOfBirth DateTime dateOfBirth DateTime
gender String gender String
nationality String nationality String
addressTH String address String
addressEN String addressEN String
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
@ -289,7 +296,6 @@ model Employee {
arrivalBarricade String arrivalBarricade String
arrivalCardNo String arrivalCardNo String
profileImageUrl String
customerBranch CustomerBranch? @relation(fields: [customerBranchId], references: [id], onDelete: SetNull) customerBranch CustomerBranch? @relation(fields: [customerBranchId], references: [id], onDelete: SetNull)
customerBranchId String? customerBranchId String?
@ -303,7 +309,7 @@ model Employee {
employeeCheckup EmployeeCheckup[] employeeCheckup EmployeeCheckup[]
employeeWork EmployeeWork[] employeeWork EmployeeWork[]
EmployeeOtherInfo EmployeeOtherInfo[] employeeOtherInfo EmployeeOtherInfo[]
} }
model EmployeeCheckup { model EmployeeCheckup {

View file

@ -23,9 +23,9 @@ type BranchCreate = {
code: string; code: string;
taxNo: string; taxNo: string;
nameEN: string; nameEN: string;
nameTH: string; name: string;
addressEN: string; addressEN: string;
addressTH: string; address: string;
zipCode: string; zipCode: string;
email: string; email: string;
telephoneNo: string; telephoneNo: string;
@ -42,9 +42,9 @@ type BranchUpdate = {
code?: string; code?: string;
taxNo?: string; taxNo?: string;
nameEN?: string; nameEN?: string;
nameTH?: string; name?: string;
addressEN?: string; addressEN?: string;
addressTH?: string; address?: string;
zipCode?: string; zipCode?: string;
email?: string; email?: string;
telephoneNo?: string; telephoneNo?: string;
@ -72,7 +72,7 @@ export class BranchController extends Controller {
select: { select: {
id: true, id: true,
nameEN: true, nameEN: true,
nameTH: true, name: true,
}, },
}); });
@ -92,7 +92,7 @@ export class BranchController extends Controller {
const where = { const where = {
OR: [ OR: [
{ nameEN: { contains: query }, zipCode }, { nameEN: { contains: query }, zipCode },
{ nameTH: { contains: query }, zipCode }, { name: { contains: query }, zipCode },
{ email: { contains: query }, zipCode }, { email: { contains: query }, zipCode },
], ],
} satisfies Prisma.BranchWhereInput; } satisfies Prisma.BranchWhereInput;

View file

@ -34,9 +34,9 @@ export class BranchUserController extends Controller {
) { ) {
const where = { const where = {
OR: [ OR: [
{ user: { firstNameTH: { contains: query }, zipCode }, branchId }, { user: { firstName: { contains: query }, zipCode }, branchId },
{ user: { firstNameEN: { contains: query }, zipCode }, branchId }, { user: { firstNameEN: { contains: query }, zipCode }, branchId },
{ user: { lastNameTH: { contains: query }, zipCode }, branchId }, { user: { lastName: { contains: query }, zipCode }, branchId },
{ user: { lastNameEN: { contains: query }, zipCode }, branchId }, { user: { lastNameEN: { contains: query }, zipCode }, branchId },
{ user: { email: { contains: query }, zipCode }, branchId }, { user: { email: { contains: query }, zipCode }, branchId },
{ user: { telephoneNo: { contains: query }, zipCode }, branchId }, { user: { telephoneNo: { contains: query }, zipCode }, branchId },
@ -131,7 +131,7 @@ export class UserBranchController extends Controller {
) { ) {
const where = { const where = {
OR: [ OR: [
{ branch: { nameTH: { contains: query }, zipCode }, userId }, { branch: { name: { contains: query }, zipCode }, userId },
{ branch: { nameEN: { contains: query }, zipCode }, userId }, { branch: { nameEN: { contains: query }, zipCode }, userId },
], ],
} satisfies Prisma.BranchUserWhereInput; } satisfies Prisma.BranchUserWhereInput;

View file

@ -32,24 +32,24 @@ type UserCreate = {
userType: string; userType: string;
userRole: string; userRole: string;
firstNameTH: string; firstName: string;
firstNameEN: string; firstNameEN: string;
lastNameTH: string; lastName: string;
lastNameEN: string; lastNameEN: string;
code: string; code?: string;
registrationNo: string; registrationNo?: string;
startDate: Date; startDate?: Date;
retireDate: Date; retireDate?: Date;
discountCondition: string; discountCondition?: string;
licenseNo: string; licenseNo?: string;
licenseIssueDate: Date; licenseIssueDate?: Date;
licenseExpireDate: Date; licenseExpireDate?: Date;
sourceNationality: string; sourceNationality?: string;
importNationality: string; importNationality?: string;
trainingPlace: string; trainingPlace?: string;
addressTH: string; address: string;
addressEN: string; addressEN: string;
zipCode: string; zipCode: string;
email: string; email: string;
@ -64,9 +64,9 @@ type UserUpdate = {
userType?: string; userType?: string;
userRole?: string; userRole?: string;
firstNameTH?: string; firstName?: string;
firstNameEN?: string; firstNameEN?: string;
lastNameTH?: string; lastName?: string;
lastNameEN?: string; lastNameEN?: string;
code?: string; code?: string;
@ -81,7 +81,7 @@ type UserUpdate = {
importNationality?: string; importNationality?: string;
trainingPlace?: string; trainingPlace?: string;
addressTH?: string; address?: string;
addressEN?: string; addressEN?: string;
zipCode?: string; zipCode?: string;
email?: string; email?: string;
@ -110,9 +110,9 @@ export class UserController extends Controller {
) { ) {
const where = { const where = {
OR: [ OR: [
{ firstNameTH: { contains: query }, zipCode, userType }, { firstName: { contains: query }, zipCode, userType },
{ firstNameEN: { contains: query }, zipCode, userType }, { firstNameEN: { contains: query }, zipCode, userType },
{ lastNameTH: { contains: query }, zipCode, userType }, { lastName: { contains: query }, zipCode, userType },
{ lastNameEN: { contains: query }, zipCode, userType }, { lastNameEN: { contains: query }, zipCode, userType },
{ email: { contains: query }, zipCode, userType }, { email: { contains: query }, zipCode, userType },
{ telephoneNo: { contains: query }, zipCode, userType }, { telephoneNo: { contains: query }, zipCode, userType },