From a7a8f47da04a26fdedede92b461c47e38a4d04c2 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 10 Jul 2024 15:01:56 +0700 Subject: [PATCH] no message --- src/controllers/ProfileController.ts | 6 +-- src/interfaces/extension.ts | 67 ++++++++++++++-------------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index aa40305c..b7fd94dd 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2079,9 +2079,9 @@ export class ProfileController extends Controller { // chkDigit = cal % 10; // } - if (citizenIdDigits[12] !== chkDigit) { - throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - } + // if (citizenIdDigits[12] !== chkDigit) { + // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); + // } } const record = await this.profileRepo.findOneBy({ id }); diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index 6efd7d5b..b08092bb 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -101,19 +101,13 @@ class Extension { } public static ToThaiFullDate2(value: Date) { let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); - return ( - value.getDate() + - " " + - Extension.ToThaiMonth(value.getMonth() + 1) + - " " + - yy - ); + return value.getDate() + " " + Extension.ToThaiMonth(value.getMonth() + 1) + " " + yy; } public static ToThaiShortDate(value: Date) { let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); return ( - "วันที่ " + + "วันที่ " + value.getDate() + " " + Extension.ToThaiShortMonth(value.getMonth() + 1) + @@ -135,7 +129,9 @@ class Extension { public static ToThaiShortDate_monthYear(value: Date) { let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear(); - return value.getDate() + " เดือน " + Extension.ToThaiMonth(value.getMonth() + 1) + " พ.ศ. " + yy; + return ( + value.getDate() + " เดือน " + Extension.ToThaiMonth(value.getMonth() + 1) + " พ.ศ. " + yy + ); } public static sumObjectValues(array: any, propertyName: any) { @@ -149,9 +145,12 @@ class Extension { } public static CheckCitizen(value: string) { - let citizen = value + let citizen = value; if (citizen.length !== 13) { - throw new HttpError(HttpStatus.NOT_FOUND, "กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก",); + throw new HttpError( + HttpStatus.NOT_FOUND, + "กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก", + ); } const citizenIdDigits = citizen.toString().split("").map(Number); const cal = @@ -171,25 +170,27 @@ class Extension { let chkDigit = 11 - calStp2; if (chkDigit === 10) { chkDigit = 1; - } - else if (chkDigit === 11) { + } else if (chkDigit === 11) { chkDigit = chkDigit % 10; } - if (citizenIdDigits[12] !== chkDigit) { - throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - } + // if (citizenIdDigits[12] !== chkDigit) { + // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); + // } return citizen; } - public static CalculateGovAge(appointDate: Date, plusYear: number = 0, subtractYear: number = 0): number { - if (appointDate == null || appointDate == undefined) return 0 + public static CalculateGovAge( + appointDate: Date, + plusYear: number = 0, + subtractYear: number = 0, + ): number { + if (appointDate == null || appointDate == undefined) return 0; const now = new Date(); if (now.getMonth() - appointDate.getMonth() >= 6) { - return (now.getFullYear() - appointDate.getFullYear()) + 1 + plusYear - subtractYear; - } - else { - return (now.getFullYear() - appointDate.getFullYear()) + plusYear - subtractYear; + return now.getFullYear() - appointDate.getFullYear() + 1 + plusYear - subtractYear; + } else { + return now.getFullYear() - appointDate.getFullYear() + plusYear - subtractYear; } } @@ -203,7 +204,7 @@ class Extension { } public static CalculateAgeStrV2(date: Date, plusYear: number = 0, subtractYear: number = 0) { - if (date == null || date == undefined) return "" + if (date == null || date == undefined) return ""; const currentDate = new Date(); if (date > currentDate) { throw new Error("วันเกิดต้องไม่มากกว่าวันที่ปัจจุบัน"); @@ -213,7 +214,10 @@ class Extension { let months = 0; let days = 0; - if (currentDate.getMonth() < date.getMonth() || (currentDate.getMonth() === date.getMonth() && currentDate.getDate() < date.getDate())) { + if ( + currentDate.getMonth() < date.getMonth() || + (currentDate.getMonth() === date.getMonth() && currentDate.getDate() < date.getDate()) + ) { years--; months = 12 - date.getMonth() + currentDate.getMonth(); @@ -222,17 +226,14 @@ class Extension { let lastMonthDays = 0; if (currentDate.getMonth() === 0) { lastMonthDays = new Date(currentDate.getFullYear() - 1, 11, 0).getDate(); - } - else { + } else { lastMonthDays = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate(); days = lastMonthDays - date.getDate() + currentDate.getDate(); } - } - else { + } else { days = currentDate.getDate() - date.getDate(); } - } - else { + } else { months = currentDate.getMonth() - date.getMonth(); if (currentDate.getDate() < date.getDate()) { @@ -240,13 +241,11 @@ class Extension { let lastMonthDays = 0; if (currentDate.getMonth() === 0) { lastMonthDays = new Date(currentDate.getFullYear() - 1, 11, 0).getDate(); - } - else { + } else { lastMonthDays = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate(); days = lastMonthDays - date.getDate() + currentDate.getDate(); } - } - else { + } else { days = currentDate.getDate() - date.getDate(); } }