From ae37e7c9552a1de12dd20c5f4260d08980d49649 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 25 Feb 2025 16:58:02 +0700 Subject: [PATCH 01/10] chore: change name --- src/controllers/09-verification-controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/09-verification-controller.ts b/src/controllers/09-verification-controller.ts index aa1bb4f..4b3809f 100644 --- a/src/controllers/09-verification-controller.ts +++ b/src/controllers/09-verification-controller.ts @@ -6,7 +6,7 @@ import { RequestWithLineUser } from "../interfaces/user"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; -type SendEmail = { +type SendOTP = { identityNumber: string; email: string; }; @@ -29,7 +29,7 @@ export class verificationController extends Controller { } @Post("/send-otp") - public async sendOTP(@Body() body: SendEmail) { + public async sendOTP(@Body() body: SendOTP) { if ( ![ process.env.SMTP_HOST, From 9590803e4046f41c5f88c8892f7bf9e924facb1b Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 25 Feb 2025 17:09:26 +0700 Subject: [PATCH 02/10] feat!: remove local build and use gitea instead --- .github/workflows/local-build-dev.yaml | 31 -------------------------- 1 file changed, 31 deletions(-) delete mode 100644 .github/workflows/local-build-dev.yaml diff --git a/.github/workflows/local-build-dev.yaml b/.github/workflows/local-build-dev.yaml deleted file mode 100644 index d4fd90a..0000000 --- a/.github/workflows/local-build-dev.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: local-build-dev - -# Intended for local network use. -# Remote access is possible if the host has a public IP address. - -on: - workflow_dispatch: - -env: - REGISTRY: ${{ vars.DOCKER_REGISTRY }} - -jobs: - local-build-dev: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - config-inline: | - [registry."${{ env.REGISTRY }}"] - http = true - insecure = true - - name: Build and Push Docker Image - uses: docker/build-push-action@v3 - with: - context: . - platforms: linux/amd64 - push: true - tags: ${{ env.REGISTRY }}/jws/jws-backend:dev - allow: security.insecure From 45482c3a1b06f76e88b5579df7b11dd2d24cbe8b Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 25 Feb 2025 17:43:41 +0700 Subject: [PATCH 03/10] fix: typos and ignore some false typos --- .typos.toml | 2 ++ src/controllers/00-doc-template-controller.ts | 4 ++-- src/controllers/08-credit-note-controller.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .typos.toml diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000..5664db5 --- /dev/null +++ b/.typos.toml @@ -0,0 +1,2 @@ +[default] +extend-ignore-re = ["(?Rm)^.*(#|//)\\s*spellchecker:disable-line$"] diff --git a/src/controllers/00-doc-template-controller.ts b/src/controllers/00-doc-template-controller.ts index 1726bf0..e375c55 100644 --- a/src/controllers/00-doc-template-controller.ts +++ b/src/controllers/00-doc-template-controller.ts @@ -341,7 +341,7 @@ function nationality(text: string, lang: "th" | "en" = "en") { case "th": return ( { - ["THA"]: "ไทย", + ["THA"]: "ไทย", // spellchecker:disable-line ["MMR"]: "เมียนมา", ["LAO"]: "ลาว", ["KHM"]: "กัมพูชา", @@ -353,7 +353,7 @@ function nationality(text: string, lang: "th" | "en" = "en") { default: return ( { - ["THA"]: "Thai", + ["THA"]: "Thai", // spellchecker:disable-line ["MMR"]: "Myanmar", ["LAO"]: "Laos", ["KHM"]: "Khmer", diff --git a/src/controllers/08-credit-note-controller.ts b/src/controllers/08-credit-note-controller.ts index b094f84..f0e3fbd 100644 --- a/src/controllers/08-credit-note-controller.ts +++ b/src/controllers/08-credit-note-controller.ts @@ -536,7 +536,7 @@ export class CreditNoteController extends Controller { if (record.creditNoteStatus !== CreditNoteStatus.Waiting) { throw new HttpError( HttpStatus.BAD_REQUEST, - "Accpeted credit note cannot be deleted", + "Accepted credit note cannot be deleted", "creditNoteAcceptedNoDelete", ); } From 9c55a37991bac851fe1181b287995c3e1fe29ccf Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 25 Feb 2025 17:56:41 +0700 Subject: [PATCH 04/10] feat: add typo check on push --- .github/workflows/spellcheck.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/spellcheck.yaml diff --git a/.github/workflows/spellcheck.yaml b/.github/workflows/spellcheck.yaml new file mode 100644 index 0000000..7a85077 --- /dev/null +++ b/.github/workflows/spellcheck.yaml @@ -0,0 +1,24 @@ +name: Spelling + +permissions: + contents: read + +on: + push: + branches: + - develop + +env: + CLICOLOR: 1 + +jobs: + spelling: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v4 + - name: Spell Check Repo + uses: crate-ci/typos@v1.29.9 + with: + files: ./src From ccbf21f71d5eba2f115a30d819f88c3480f68d82 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:32:23 +0700 Subject: [PATCH 05/10] refactor: workflows --- .../gitea-local.yaml => .forgejo/workflows/deploy.yaml | 4 +--- {.github => .forgejo}/workflows/spellcheck.yaml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) rename .github/workflows/gitea-local.yaml => .forgejo/workflows/deploy.yaml (98%) rename {.github => .forgejo}/workflows/spellcheck.yaml (95%) diff --git a/.github/workflows/gitea-local.yaml b/.forgejo/workflows/deploy.yaml similarity index 98% rename from .github/workflows/gitea-local.yaml rename to .forgejo/workflows/deploy.yaml index 6b2afdb..c5bc33c 100644 --- a/.github/workflows/gitea-local.yaml +++ b/.forgejo/workflows/deploy.yaml @@ -1,9 +1,7 @@ -name: Gitea Action +name: Deploy Local run-name: Build ${{ github.actor }} -# Intended for local gitea instance only. - on: workflow_dispatch: diff --git a/.github/workflows/spellcheck.yaml b/.forgejo/workflows/spellcheck.yaml similarity index 95% rename from .github/workflows/spellcheck.yaml rename to .forgejo/workflows/spellcheck.yaml index 7a85077..6b36c63 100644 --- a/.github/workflows/spellcheck.yaml +++ b/.forgejo/workflows/spellcheck.yaml @@ -1,4 +1,4 @@ -name: Spelling +name: Spell Check permissions: contents: read From 6f1969c829aae67c4201badaadaa4533b29daf1e Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:49:35 +0700 Subject: [PATCH 06/10] fix: line user not registered for all customer branch --- src/controllers/09-line-controller.ts | 82 +++++++++++++++++-- src/controllers/09-verification-controller.ts | 21 +++-- 2 files changed, 89 insertions(+), 14 deletions(-) diff --git a/src/controllers/09-line-controller.ts b/src/controllers/09-line-controller.ts index 16028fc..879b00e 100644 --- a/src/controllers/09-line-controller.ts +++ b/src/controllers/09-line-controller.ts @@ -73,7 +73,14 @@ export class LineController extends Controller { status: activeOnly ? { not: Status.INACTIVE } : undefined, id: customerBranchId, customerId, - userId: line.user.sub, + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], }, subDistrict: zipCode ? { zipCode } : undefined, gender, @@ -135,7 +142,14 @@ export class LineController extends Controller { where: { id: employeeId, customerBranch: { - userId: line.user.sub, + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], }, }, }); @@ -220,7 +234,16 @@ export class LineController extends Controller { // registeredBranch: { OR: permissionCond(req.user) }, }, employee: { - customerBranch: { userId: line.user.sub }, + customerBranch: { + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], + }, }, } satisfies Prisma.RequestDataWhereInput; @@ -282,7 +305,16 @@ export class LineController extends Controller { where: { id: requestDataId, employee: { - customerBranch: { userId: line.user.sub }, + customerBranch: { + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], + }, }, }, include: { @@ -399,7 +431,16 @@ export class LineController extends Controller { : undefined, quotationId, employee: { - customerBranch: { userId: line.user.sub }, + customerBranch: { + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], + }, }, }, } satisfies Prisma.RequestWorkWhereInput; @@ -519,7 +560,16 @@ export class LineController extends Controller { id: requestWorkId, request: { employee: { - customerBranch: { userId: line.user.sub }, + customerBranch: { + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], + }, }, }, }, @@ -588,7 +638,14 @@ export class LineController extends Controller { payCondition, quotationStatus: historyOnly ? { in: ["ProcessComplete", "Canceled"] } : status, customerBranch: { - userId: line.user.sub, + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], }, requestData: inProgressOnly ? { @@ -698,7 +755,16 @@ export class LineController extends Controller { where: { id: quotationId, isDebitNote: false, - customerBranch: { userId: line.user.sub }, + customerBranch: { + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], + }, }, }); diff --git a/src/controllers/09-verification-controller.ts b/src/controllers/09-verification-controller.ts index 4b3809f..1222eef 100644 --- a/src/controllers/09-verification-controller.ts +++ b/src/controllers/09-verification-controller.ts @@ -25,7 +25,18 @@ export class verificationController extends Controller { @Get() @Security("line") async isRegistered(@Request() req: RequestWithLineUser) { - return !!(await prisma.customerBranch.findFirst({ where: { userId: req.user.sub } })); + return !!(await prisma.customerBranch.findFirst({ + where: { + OR: [ + { userId: req.user.sub }, + { + customer: { + branch: { some: { userId: req.user.sub } }, + }, + }, + ], + }, + })); } @Post("/send-otp") @@ -133,13 +144,11 @@ export class verificationController extends Controller { customerBranch.otpExpires && customerBranch.otpExpires >= new Date() ) { - const dataCustomer = await prisma.customerBranch.update({ + const dataCustomer = await prisma.customerBranch.updateMany({ where: { - id: customerBranch.id, - }, - data: { - userId: req.user.sub, + customerId: customerBranch.customerId, }, + data: { userId: req.user.sub }, }); return dataCustomer; From d373c8dbf9ef51e1ab79f9298a68398eb9ebb0d7 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:55:55 +0700 Subject: [PATCH 07/10] refactor(ci): remove run name --- .forgejo/workflows/deploy.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.forgejo/workflows/deploy.yaml b/.forgejo/workflows/deploy.yaml index c5bc33c..7306749 100644 --- a/.forgejo/workflows/deploy.yaml +++ b/.forgejo/workflows/deploy.yaml @@ -1,7 +1,5 @@ name: Deploy Local -run-name: Build ${{ github.actor }} - on: workflow_dispatch: From afa2808a0c0435114fd485abbd5556cdc17fb18e Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 26 Feb 2025 14:00:11 +0700 Subject: [PATCH 08/10] refactor: query parameter --- src/controllers/09-line-controller.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/09-line-controller.ts b/src/controllers/09-line-controller.ts index 879b00e..0c982c5 100644 --- a/src/controllers/09-line-controller.ts +++ b/src/controllers/09-line-controller.ts @@ -597,6 +597,8 @@ export class LineController extends Controller { @Query() pendingOnly?: boolean, @Query() inProgressOnly?: boolean, @Query() historyOnly?: boolean, + @Query() successOnly?: boolean, + @Query() canceledOnly?: boolean, @Query() urgentFirst?: boolean, @Query() includeRegisteredBranch?: boolean, @Query() code?: string, @@ -636,7 +638,7 @@ export class LineController extends Controller { isDebitNote: false, code, payCondition, - quotationStatus: historyOnly ? { in: ["ProcessComplete", "Canceled"] } : status, + quotationStatus: successOnly ? "ProcessComplete" : canceledOnly ? "Canceled" : status, customerBranch: { OR: [ { userId: line.user.sub }, @@ -656,6 +658,8 @@ export class LineController extends Controller { : undefined, } satisfies Prisma.QuotationWhereInput; + console.log(); + const [result, total] = await prisma.$transaction([ prisma.quotation.findMany({ where, From e2023ab0ed5caeacd498fc181c0037db976c8332 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 26 Feb 2025 14:03:24 +0700 Subject: [PATCH 09/10] chore: clean unused --- src/controllers/09-line-controller.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/controllers/09-line-controller.ts b/src/controllers/09-line-controller.ts index 0c982c5..942120c 100644 --- a/src/controllers/09-line-controller.ts +++ b/src/controllers/09-line-controller.ts @@ -596,7 +596,6 @@ export class LineController extends Controller { @Query() status?: QuotationStatus, @Query() pendingOnly?: boolean, @Query() inProgressOnly?: boolean, - @Query() historyOnly?: boolean, @Query() successOnly?: boolean, @Query() canceledOnly?: boolean, @Query() urgentFirst?: boolean, From bf9dac8d46255c58b8496528ab226d666b0158fc Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 26 Feb 2025 14:13:28 +0700 Subject: [PATCH 10/10] fix: empty array cause result to be zero --- src/controllers/09-line-controller.ts | 63 ++++++++++++++------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/controllers/09-line-controller.ts b/src/controllers/09-line-controller.ts index 942120c..7704c4d 100644 --- a/src/controllers/09-line-controller.ts +++ b/src/controllers/09-line-controller.ts @@ -604,36 +604,39 @@ export class LineController extends Controller { @Query() query = "", ) { const where = { - OR: [ - ...(queryOrNot(query, [ - { code: { contains: query, mode: "insensitive" } }, - { workName: { contains: query } }, - { - customerBranch: { - OR: [ + OR: + query || pendingOnly + ? [ + ...(queryOrNot(query, [ { code: { contains: query, mode: "insensitive" } }, - { customerName: { contains: query } }, - { firstName: { contains: query } }, - { firstNameEN: { contains: query } }, - { lastName: { contains: query } }, - { lastNameEN: { contains: query } }, - ], - }, - }, - ]) || []), - ...(queryOrNot(!!pendingOnly, [ - { - requestData: { - some: { - requestDataStatus: "Pending", - }, - }, - }, - { - requestData: { none: {} }, - }, - ]) || []), - ], + { workName: { contains: query } }, + { + customerBranch: { + OR: [ + { code: { contains: query, mode: "insensitive" } }, + { customerName: { contains: query } }, + { firstName: { contains: query } }, + { firstNameEN: { contains: query } }, + { lastName: { contains: query } }, + { lastNameEN: { contains: query } }, + ], + }, + }, + ]) || []), + ...(queryOrNot(!!pendingOnly, [ + { + requestData: { + some: { + requestDataStatus: "Pending", + }, + }, + }, + { + requestData: { none: {} }, + }, + ]) || []), + ] + : undefined, isDebitNote: false, code, payCondition, @@ -657,8 +660,6 @@ export class LineController extends Controller { : undefined, } satisfies Prisma.QuotationWhereInput; - console.log(); - const [result, total] = await prisma.$transaction([ prisma.quotation.findMany({ where,