diff --git a/.github/workflows/gitea-local.yaml b/.forgejo/workflows/deploy.yaml similarity index 97% rename from .github/workflows/gitea-local.yaml rename to .forgejo/workflows/deploy.yaml index 6b2afdb..7306749 100644 --- a/.github/workflows/gitea-local.yaml +++ b/.forgejo/workflows/deploy.yaml @@ -1,8 +1,4 @@ -name: Gitea Action - -run-name: Build ${{ github.actor }} - -# Intended for local gitea instance only. +name: Deploy Local on: workflow_dispatch: diff --git a/.forgejo/workflows/spellcheck.yaml b/.forgejo/workflows/spellcheck.yaml new file mode 100644 index 0000000..6b36c63 --- /dev/null +++ b/.forgejo/workflows/spellcheck.yaml @@ -0,0 +1,24 @@ +name: Spell Check + +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 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 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", ); } diff --git a/src/controllers/09-line-controller.ts b/src/controllers/09-line-controller.ts index 16028fc..7704c4d 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 } }, + }, + }, + ], + }, }, }, }, @@ -546,49 +596,60 @@ 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, @Query() includeRegisteredBranch?: boolean, @Query() code?: string, @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, - quotationStatus: historyOnly ? { in: ["ProcessComplete", "Canceled"] } : status, + quotationStatus: successOnly ? "ProcessComplete" : canceledOnly ? "Canceled" : status, customerBranch: { - userId: line.user.sub, + OR: [ + { userId: line.user.sub }, + { + customer: { + branch: { some: { userId: line.user.sub } }, + }, + }, + ], }, requestData: inProgressOnly ? { @@ -698,7 +759,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 aa1bb4f..1222eef 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; }; @@ -25,11 +25,22 @@ 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") - public async sendOTP(@Body() body: SendEmail) { + public async sendOTP(@Body() body: SendOTP) { if ( ![ process.env.SMTP_HOST, @@ -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;