From d31093eba2ae75c3176314505f827e4aa9a92334 Mon Sep 17 00:00:00 2001 From: Fityan <63894003+fityannugroho@users.noreply.github.com> Date: Sat, 23 Nov 2024 15:11:40 +0700 Subject: [PATCH] chore: update code style configuration (#467) --- CONTRIBUTING.md | 2 +- biome.json | 64 +++---------------- prisma/mongodb/seeder.ts | 5 -- prisma/seed.ts | 4 +- src/common/config/app.ts | 7 +- src/common/decorator/EqualsAny.ts | 4 +- src/common/decorator/IsNotSymbol.ts | 4 +- .../api-paginated-response.decorator.ts | 2 +- .../interceptor/transform.interceptor.ts | 4 +- src/common/utils/__tests__/package.spec.ts | 4 +- src/common/utils/coordinate.ts | 6 +- src/common/utils/data.ts | 4 +- src/common/utils/db/index.ts | 11 ++-- src/common/utils/runner.ts | 2 +- src/district/district.controller.ts | 4 +- src/district/district.dto.ts | 6 +- src/district/district.module.ts | 2 +- src/district/district.service.spec.ts | 2 +- src/island/island.controller.ts | 4 +- src/island/island.dto.ts | 6 +- src/island/island.service.spec.ts | 12 ++-- src/main.ts | 2 +- src/prisma/__mocks__/prisma.service.ts | 4 +- src/prisma/prisma.service.spec.ts | 2 +- src/province/province.controller.ts | 4 +- src/province/province.dto.ts | 2 +- src/province/province.module.ts | 2 +- src/province/province.service.spec.ts | 2 +- src/regency/regency.controller.ts | 4 +- src/regency/regency.dto.ts | 4 +- src/regency/regency.module.ts | 4 +- src/regency/regency.service.spec.ts | 12 ++-- src/regency/regency.service.ts | 2 +- src/village/village.controller.ts | 4 +- src/village/village.service.spec.ts | 14 ++-- test/district.e2e-spec.ts | 12 ++-- test/helper/data-regex.ts | 2 +- test/island.e2e-spec.ts | 16 ++--- test/province.e2e-spec.ts | 8 +-- test/regency.e2e-spec.ts | 8 +-- test/village.e2e-spec.ts | 12 ++-- vitest.config.e2e.mts | 2 +- vitest.config.mts | 2 +- 43 files changed, 117 insertions(+), 166 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0c07f0f..43f477e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,7 +21,7 @@ To ensure consistency throughout the source code, keep these rules in mind as you are working: - All features or bug fixes must be tested by one or more specs (unit-tests). -- We follow [Google's JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html), but wrap all code at 100 characters. An automated formatter is available (`pnpm run lint:fix`). +- We use [Biome.js](https://biomejs.dev) to manage code style (both linter and formatter). An automated command is available (`pnpm run lint:fix`). ## Commit Message Guidelines diff --git a/biome.json b/biome.json index 63a6c58..ad65c33 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/1.9.3/schema.json", + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", "vcs": { "enabled": false, "clientKind": "git", @@ -21,40 +21,28 @@ "bracketSpacing": true }, "organizeImports": { - "enabled": false + "enabled": true }, "linter": { "enabled": true, "rules": { - "recommended": false, - "complexity": { - "noBannedTypes": "error", - "noUselessTypeConstraint": "error" - }, + "recommended": true, "correctness": { - "noPrecisionLoss": "error", "noUnusedVariables": "error", - "useArrayLiterals": "off" + "useArrayLiterals": "error" }, "style": { - "noInferrableTypes": "error", "noNamespace": "error", - "useAsConstAssertion": "error", - "useBlockStatements": "off", + "useBlockStatements": "error", "useConsistentArrayType": "error", "useForOf": "error", - "useShorthandFunctionType": "error" + "useImportType": "off" }, "suspicious": { "noEmptyBlockStatements": "error", - "noExplicitAny": "off", - "noExtraNonNullAssertion": "error", - "noMisleadingInstantiator": "error", - "noUnsafeDeclarationMerging": "error", - "useNamespaceKeyword": "error" + "noExplicitAny": "off" } - }, - "ignore": ["**/node_modules", "**/dist", "**/.eslintrc.js"] + } }, "javascript": { "formatter": { @@ -71,39 +59,5 @@ "parser": { "unsafeParameterDecoratorsEnabled": true } - }, - "overrides": [ - { - "include": ["*.ts", "*.tsx", "*.mts", "*.cts"], - "linter": { - "rules": { - "correctness": { - "noConstAssign": "off", - "noGlobalObjectCalls": "off", - "noInvalidConstructorSuper": "off", - "noNewSymbol": "off", - "noSetterReturn": "off", - "noUndeclaredVariables": "off", - "noUnreachable": "off", - "noUnreachableSuper": "off" - }, - "style": { - "noArguments": "error", - "noVar": "error", - "useConst": "error" - }, - "suspicious": { - "noDuplicateClassMembers": "off", - "noDuplicateObjectKeys": "off", - "noDuplicateParameters": "off", - "noFunctionAssign": "off", - "noImportAssign": "off", - "noRedeclare": "off", - "noUnsafeNegation": "off", - "useGetterReturn": "off" - } - } - } - } - ] + } } diff --git a/prisma/mongodb/seeder.ts b/prisma/mongodb/seeder.ts index b747673..e1d0013 100644 --- a/prisma/mongodb/seeder.ts +++ b/prisma/mongodb/seeder.ts @@ -1,11 +1,6 @@ -import { PrismaClient } from '@prisma/client'; import { Area, Seeder } from '../seeder'; export class MongodbSeeder extends Seeder { - constructor(prisma: PrismaClient) { - super(prisma); - } - async deleteAreas(area: Area): Promise { const mongoCollectionMap = { province: 'provinces', diff --git a/prisma/seed.ts b/prisma/seed.ts index 86da003..defc4a1 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,8 +1,8 @@ import { dbConfig } from '@/common/config/db'; -import { timify } from '@/common/utils/timify'; -import { PrismaClient } from '@prisma/client'; import { validateDBConfig } from '@/common/utils/db'; import { dbProvider } from '@/common/utils/db/provider'; +import { timify } from '@/common/utils/timify'; +import { PrismaClient } from '@prisma/client'; import { MongodbSeeder } from './mongodb/seeder'; import { Seeder } from './seeder'; diff --git a/src/common/config/app.ts b/src/common/config/app.ts index cda71e2..8be7bc1 100644 --- a/src/common/config/app.ts +++ b/src/common/config/app.ts @@ -27,10 +27,11 @@ export type AppConfig = { export const appConfig: AppConfig = { env: (process.env.APP_ENV as AppConfig['env']) || 'dev', host: process.env.APP_HOST || '0.0.0.0', - port: parseInt(process.env.APP_PORT) || 3000, + port: Number.parseInt(process.env.APP_PORT) || 3000, pagination: { - maxPageSize: parseInt(process.env.APP_PAGINATION_MAX_PAGE_SIZE) || 100, + maxPageSize: + Number.parseInt(process.env.APP_PAGINATION_MAX_PAGE_SIZE) || 100, defaultPageSize: - parseInt(process.env.APP_PAGINATION_DEFAULT_PAGE_SIZE) || 10, + Number.parseInt(process.env.APP_PAGINATION_DEFAULT_PAGE_SIZE) || 10, }, } as const; diff --git a/src/common/decorator/EqualsAny.ts b/src/common/decorator/EqualsAny.ts index 58fb7f6..e23a0fd 100644 --- a/src/common/decorator/EqualsAny.ts +++ b/src/common/decorator/EqualsAny.ts @@ -1,9 +1,9 @@ import { - registerDecorator, ValidationArguments, ValidationOptions, ValidatorConstraint, ValidatorConstraintInterface, + registerDecorator, } from 'class-validator'; /** @@ -15,7 +15,7 @@ export function EqualsAny( validValues: string[], validationOptions?: ValidationOptions, ) { - return function (object: object, propertyName: string) { + return (object: object, propertyName: string) => { registerDecorator({ target: object.constructor, propertyName: propertyName, diff --git a/src/common/decorator/IsNotSymbol.ts b/src/common/decorator/IsNotSymbol.ts index b2754ae..739d96d 100644 --- a/src/common/decorator/IsNotSymbol.ts +++ b/src/common/decorator/IsNotSymbol.ts @@ -1,9 +1,9 @@ import { - registerDecorator, ValidationArguments, ValidationOptions, ValidatorConstraint, ValidatorConstraintInterface, + registerDecorator, } from 'class-validator'; /** @@ -17,7 +17,7 @@ export function IsNotSymbol( allowedSymbols?: string, validationOptions?: ValidationOptions, ) { - return function (object: object, propertyName: string) { + return (object: object, propertyName: string) => { registerDecorator({ target: object.constructor, propertyName: propertyName, diff --git a/src/common/decorator/api-paginated-response.decorator.ts b/src/common/decorator/api-paginated-response.decorator.ts index 5083a9d..f79a940 100644 --- a/src/common/decorator/api-paginated-response.decorator.ts +++ b/src/common/decorator/api-paginated-response.decorator.ts @@ -4,8 +4,8 @@ import { UseInterceptors, applyDecorators, } from '@nestjs/common'; -import { PaginateInterceptor } from '../interceptor/paginate.interceptor'; import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger'; +import { PaginateInterceptor } from '../interceptor/paginate.interceptor'; type Options> = { /** diff --git a/src/common/interceptor/transform.interceptor.ts b/src/common/interceptor/transform.interceptor.ts index e50dc56..ef72016 100644 --- a/src/common/interceptor/transform.interceptor.ts +++ b/src/common/interceptor/transform.interceptor.ts @@ -1,8 +1,8 @@ import { + CallHandler, + ExecutionContext, Injectable, NestInterceptor, - ExecutionContext, - CallHandler, } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { Observable } from 'rxjs'; diff --git a/src/common/utils/__tests__/package.spec.ts b/src/common/utils/__tests__/package.spec.ts index bcf7092..a1764e7 100644 --- a/src/common/utils/__tests__/package.spec.ts +++ b/src/common/utils/__tests__/package.spec.ts @@ -1,6 +1,6 @@ -import { describe, it, expect, vi } from 'vitest'; -import { getInstalledPackageVersion } from '../package'; import { exec } from 'node:child_process'; +import { describe, expect, it, vi } from 'vitest'; +import { getInstalledPackageVersion } from '../package'; vi.mock('node:child_process', () => ({ exec: vi.fn(), diff --git a/src/common/utils/coordinate.ts b/src/common/utils/coordinate.ts index e970daf..1f919cf 100644 --- a/src/common/utils/coordinate.ts +++ b/src/common/utils/coordinate.ts @@ -27,9 +27,9 @@ const calculate = ( pole: string, ) => { return ( - (parseFloat(degrees) + - parseFloat(minutes) / 60 + - parseFloat(seconds) / 3600) * + (Number.parseFloat(degrees) + + Number.parseFloat(minutes) / 60 + + Number.parseFloat(seconds) / 3600) * (['N', 'E'].includes(pole) ? 1 : -1) ); }; diff --git a/src/common/utils/data.ts b/src/common/utils/data.ts index c32454a..374c171 100644 --- a/src/common/utils/data.ts +++ b/src/common/utils/data.ts @@ -77,8 +77,8 @@ export function getIslands() { values: { code: removeDots, regency_code: (value) => (value === '' ? null : removeDots(value)), - is_outermost_small: (value) => !!parseInt(value, 10), - is_populated: (value) => !!parseInt(value, 10), + is_outermost_small: (value) => !!Number.parseInt(value, 10), + is_populated: (value) => !!Number.parseInt(value, 10), }, }, }); diff --git a/src/common/utils/db/index.ts b/src/common/utils/db/index.ts index 35b13fd..b151406 100644 --- a/src/common/utils/db/index.ts +++ b/src/common/utils/db/index.ts @@ -12,19 +12,20 @@ import { DBProviderFeatures, dbProviderConfig } from './provider'; * @throws If there are any invalid config value. */ export const validateDBConfig = (...vars: (keyof typeof dbConfig)[]) => { - if (vars.length === 0) { - vars = Object.keys(dbConfig) as (keyof typeof dbConfig)[]; - } + const configVars = + vars.length === 0 + ? (Object.keys(dbConfig) as (keyof typeof dbConfig)[]) + : vars; if (!dbConfig.provider) { throw new DatabaseConfigError('`DB_PROVIDER` is not defined.'); } if (!dbProviderConfig[dbConfig.provider]) { - throw new DatabaseConfigError(`\`DB_PROVIDER\` is not supported.`); + throw new DatabaseConfigError('`DB_PROVIDER` is not supported.'); } - if (vars.includes('url')) { + if (configVars.includes('url')) { if (!dbConfig.url) { throw new DatabaseConfigError('`DB_URL` is not defined.'); } diff --git a/src/common/utils/runner.ts b/src/common/utils/runner.ts index a937f2e..d242aa3 100644 --- a/src/common/utils/runner.ts +++ b/src/common/utils/runner.ts @@ -1,4 +1,4 @@ -import { exec } from 'child_process'; +import { exec } from 'node:child_process'; const run = (command: string) => new Promise<{ stdout: string; stderr: string }>((resolve, reject) => { diff --git a/src/district/district.controller.ts b/src/district/district.controller.ts index 33d3864..ea4ce47 100644 --- a/src/district/district.controller.ts +++ b/src/district/district.controller.ts @@ -1,4 +1,6 @@ import { ApiDataResponse } from '@/common/decorator/api-data-response.decorator'; +import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; +import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; import { Controller, Get, @@ -19,8 +21,6 @@ import { DistrictWithParent, } from './district.dto'; import { DistrictService } from './district.service'; -import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; -import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; @Controller('districts') export class DistrictController { diff --git a/src/district/district.dto.ts b/src/district/district.dto.ts index 978e65c..1a329d5 100644 --- a/src/district/district.dto.ts +++ b/src/district/district.dto.ts @@ -1,5 +1,8 @@ import { EqualsAny } from '@/common/decorator/EqualsAny'; import { IsNotSymbol } from '@/common/decorator/IsNotSymbol'; +import { PaginationQuery } from '@/common/dto/pagination.dto'; +import { Province } from '@/province/province.dto'; +import { Regency } from '@/regency/regency.dto'; import { SortQuery } from '@/sort/sort.dto'; import { ApiProperty, @@ -8,9 +11,6 @@ import { PickType, } from '@nestjs/swagger'; import { IsNotEmpty, IsNumberString, Length, MaxLength } from 'class-validator'; -import { PaginationQuery } from '@/common/dto/pagination.dto'; -import { Regency } from '@/regency/regency.dto'; -import { Province } from '@/province/province.dto'; export class District { @IsNotEmpty() diff --git a/src/district/district.module.ts b/src/district/district.module.ts index 2f37e65..219af4f 100644 --- a/src/district/district.module.ts +++ b/src/district/district.module.ts @@ -1,8 +1,8 @@ import { PrismaModule } from '@/prisma/prisma.module'; +import { VillageModule } from '@/village/village.module'; import { Module } from '@nestjs/common'; import { DistrictController } from './district.controller'; import { DistrictService } from './district.service'; -import { VillageModule } from '@/village/village.module'; @Module({ imports: [PrismaModule, VillageModule], diff --git a/src/district/district.service.spec.ts b/src/district/district.service.spec.ts index 202e29b..0de023d 100644 --- a/src/district/district.service.spec.ts +++ b/src/district/district.service.spec.ts @@ -1,11 +1,11 @@ import { getDistricts, getProvinces, getRegencies } from '@/common/utils/data'; import { getDBProviderFeatures } from '@/common/utils/db'; +import { mockPrismaService } from '@/prisma/__mocks__/prisma.service'; import { SortOrder } from '@/sort/sort.dto'; import { Test, TestingModule } from '@nestjs/testing'; import { District, Province, Regency } from '@prisma/client'; import { PrismaService } from '../prisma/prisma.service'; import { DistrictService } from './district.service'; -import { mockPrismaService } from '@/prisma/__mocks__/prisma.service'; describe('DistrictService', () => { let districts: District[]; diff --git a/src/island/island.controller.ts b/src/island/island.controller.ts index 11c5212..dceab30 100644 --- a/src/island/island.controller.ts +++ b/src/island/island.controller.ts @@ -1,4 +1,6 @@ import { ApiDataResponse } from '@/common/decorator/api-data-response.decorator'; +import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; +import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; import { Controller, Get, @@ -19,8 +21,6 @@ import { IslandWithParent, } from './island.dto'; import { IslandService } from './island.service'; -import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; -import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; @Controller('islands') export class IslandController { diff --git a/src/island/island.dto.ts b/src/island/island.dto.ts index 303a9d4..4caf520 100644 --- a/src/island/island.dto.ts +++ b/src/island/island.dto.ts @@ -1,3 +1,6 @@ +import { PaginationQuery } from '@/common/dto/pagination.dto'; +import { Province } from '@/province/province.dto'; +import { Regency } from '@/regency/regency.dto'; import { SortQuery } from '@/sort/sort.dto'; import { ApiProperty, @@ -17,9 +20,6 @@ import { } from 'class-validator'; import { EqualsAny } from '../common/decorator/EqualsAny'; import { IsNotSymbol } from '../common/decorator/IsNotSymbol'; -import { PaginationQuery } from '@/common/dto/pagination.dto'; -import { Regency } from '@/regency/regency.dto'; -import { Province } from '@/province/province.dto'; export class Island { @IsNotEmpty() diff --git a/src/island/island.service.spec.ts b/src/island/island.service.spec.ts index 5f74840..50c7c19 100644 --- a/src/island/island.service.spec.ts +++ b/src/island/island.service.spec.ts @@ -1,11 +1,11 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { IslandService } from './island.service'; -import { PrismaService } from '@/prisma/prisma.service'; -import { Island, Province, Regency } from '@prisma/client'; +import { getProvinces, getRegencies } from '@/common/utils/data'; import { getDBProviderFeatures } from '@/common/utils/db'; -import { SortOrder } from '@/sort/sort.dto'; import { mockPrismaService } from '@/prisma/__mocks__/prisma.service'; -import { getProvinces, getRegencies } from '@/common/utils/data'; +import { PrismaService } from '@/prisma/prisma.service'; +import { SortOrder } from '@/sort/sort.dto'; +import { Test, TestingModule } from '@nestjs/testing'; +import { Island, Province, Regency } from '@prisma/client'; +import { IslandService } from './island.service'; const islands: readonly Island[] = [ { diff --git a/src/main.ts b/src/main.ts index 634d082..647b9fe 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,3 +1,4 @@ +import { appConfig } from '@/common/config/app'; import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { @@ -5,7 +6,6 @@ import { NestFastifyApplication, } from '@nestjs/platform-fastify'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; -import { appConfig } from '@/common/config/app'; import { AppModule } from './app.module'; async function bootstrap() { diff --git a/src/prisma/__mocks__/prisma.service.ts b/src/prisma/__mocks__/prisma.service.ts index 493873a..dcfec56 100644 --- a/src/prisma/__mocks__/prisma.service.ts +++ b/src/prisma/__mocks__/prisma.service.ts @@ -1,6 +1,6 @@ -import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; -import { Models, Model, PaginatorOptions } from '../prisma.interface'; import { appConfig } from '@/common/config/app'; +import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; +import { Model, Models, PaginatorOptions } from '../prisma.interface'; export const mockPrismaService = ( model: M, diff --git a/src/prisma/prisma.service.spec.ts b/src/prisma/prisma.service.spec.ts index 3acde31..7373175 100644 --- a/src/prisma/prisma.service.spec.ts +++ b/src/prisma/prisma.service.spec.ts @@ -1,6 +1,6 @@ +import { appConfig } from '@/common/config/app'; import { Test } from '@nestjs/testing'; import { PrismaClient, Province } from '@prisma/client'; -import { appConfig } from '@/common/config/app'; import { PaginatorOptions } from './prisma.interface'; import { PrismaService } from './prisma.service'; diff --git a/src/province/province.controller.ts b/src/province/province.controller.ts index eee39f6..8dfab26 100644 --- a/src/province/province.controller.ts +++ b/src/province/province.controller.ts @@ -1,4 +1,6 @@ import { ApiDataResponse } from '@/common/decorator/api-data-response.decorator'; +import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; +import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; import { Controller, Get, @@ -18,8 +20,6 @@ import { ProvinceFindQueries, } from './province.dto'; import { ProvinceService } from './province.service'; -import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; -import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; @Controller('provinces') export class ProvinceController { diff --git a/src/province/province.dto.ts b/src/province/province.dto.ts index b91d944..453e739 100644 --- a/src/province/province.dto.ts +++ b/src/province/province.dto.ts @@ -1,5 +1,6 @@ import { EqualsAny } from '@/common/decorator/EqualsAny'; import { IsNotSymbol } from '@/common/decorator/IsNotSymbol'; +import { PaginationQuery } from '@/common/dto/pagination.dto'; import { SortQuery } from '@/sort/sort.dto'; import { ApiProperty, @@ -8,7 +9,6 @@ import { PickType, } from '@nestjs/swagger'; import { IsNotEmpty, IsNumberString, Length, MaxLength } from 'class-validator'; -import { PaginationQuery } from '@/common/dto/pagination.dto'; export class Province { @IsNotEmpty() diff --git a/src/province/province.module.ts b/src/province/province.module.ts index 600cf81..8f8188e 100644 --- a/src/province/province.module.ts +++ b/src/province/province.module.ts @@ -1,8 +1,8 @@ import { PrismaModule } from '@/prisma/prisma.module'; +import { RegencyModule } from '@/regency/regency.module'; import { Module } from '@nestjs/common'; import { ProvinceController } from './province.controller'; import { ProvinceService } from './province.service'; -import { RegencyModule } from '@/regency/regency.module'; @Module({ imports: [PrismaModule, RegencyModule], diff --git a/src/province/province.service.spec.ts b/src/province/province.service.spec.ts index 662ab1e..683d99d 100644 --- a/src/province/province.service.spec.ts +++ b/src/province/province.service.spec.ts @@ -1,11 +1,11 @@ import { getProvinces } from '@/common/utils/data'; import { getDBProviderFeatures } from '@/common/utils/db'; +import { mockPrismaService } from '@/prisma/__mocks__/prisma.service'; import { PrismaService } from '@/prisma/prisma.service'; import { SortOrder } from '@/sort/sort.dto'; import { Test, TestingModule } from '@nestjs/testing'; import { Province } from '@prisma/client'; import { ProvinceService } from './province.service'; -import { mockPrismaService } from '@/prisma/__mocks__/prisma.service'; describe('ProvinceService', () => { let provinces: readonly Province[]; diff --git a/src/regency/regency.controller.ts b/src/regency/regency.controller.ts index 2223016..9bc807f 100644 --- a/src/regency/regency.controller.ts +++ b/src/regency/regency.controller.ts @@ -1,5 +1,6 @@ import { ApiDataResponse } from '@/common/decorator/api-data-response.decorator'; import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; +import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; import { Controller, Get, @@ -16,11 +17,10 @@ import { import { Regency, RegencyFindByCodeParams, - RegencyWithParent, RegencyFindQueries, + RegencyWithParent, } from './regency.dto'; import { RegencyService } from './regency.service'; -import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; @Controller('regencies') export class RegencyController { diff --git a/src/regency/regency.dto.ts b/src/regency/regency.dto.ts index 2ddfb96..adad504 100644 --- a/src/regency/regency.dto.ts +++ b/src/regency/regency.dto.ts @@ -1,5 +1,7 @@ import { EqualsAny } from '@/common/decorator/EqualsAny'; import { IsNotSymbol } from '@/common/decorator/IsNotSymbol'; +import { PaginationQuery } from '@/common/dto/pagination.dto'; +import { Province } from '@/province/province.dto'; import { SortQuery } from '@/sort/sort.dto'; import { ApiProperty, @@ -8,8 +10,6 @@ import { PickType, } from '@nestjs/swagger'; import { IsNotEmpty, IsNumberString, Length, MaxLength } from 'class-validator'; -import { PaginationQuery } from '@/common/dto/pagination.dto'; -import { Province } from '@/province/province.dto'; export class Regency { @IsNotEmpty() diff --git a/src/regency/regency.module.ts b/src/regency/regency.module.ts index ceb3ab3..6a5c28e 100644 --- a/src/regency/regency.module.ts +++ b/src/regency/regency.module.ts @@ -1,9 +1,9 @@ +import { DistrictModule } from '@/district/district.module'; +import { PrismaModule } from '@/prisma/prisma.module'; import { Module } from '@nestjs/common'; import { IslandModule } from '../island/island.module'; import { RegencyController } from './regency.controller'; import { RegencyService } from './regency.service'; -import { PrismaModule } from '@/prisma/prisma.module'; -import { DistrictModule } from '@/district/district.module'; @Module({ imports: [PrismaModule, DistrictModule, IslandModule], diff --git a/src/regency/regency.service.spec.ts b/src/regency/regency.service.spec.ts index 9dc8566..81a1365 100644 --- a/src/regency/regency.service.spec.ts +++ b/src/regency/regency.service.spec.ts @@ -1,11 +1,11 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { PrismaService } from '@/prisma/prisma.service'; -import { RegencyService } from './regency.service'; -import { Province, Regency } from '@prisma/client'; -import { getDBProviderFeatures } from '@/common/utils/db'; -import { SortOrder } from '@/sort/sort.dto'; import { getProvinces, getRegencies } from '@/common/utils/data'; +import { getDBProviderFeatures } from '@/common/utils/db'; import { mockPrismaService } from '@/prisma/__mocks__/prisma.service'; +import { PrismaService } from '@/prisma/prisma.service'; +import { SortOrder } from '@/sort/sort.dto'; +import { Test, TestingModule } from '@nestjs/testing'; +import { Province, Regency } from '@prisma/client'; +import { RegencyService } from './regency.service'; describe('RegencyService', () => { let regencies: Regency[]; diff --git a/src/regency/regency.service.ts b/src/regency/regency.service.ts index d03bb89..bfd991f 100644 --- a/src/regency/regency.service.ts +++ b/src/regency/regency.service.ts @@ -4,7 +4,7 @@ import { PrismaService } from '@/prisma/prisma.service'; import { SortService } from '@/sort/sort.service'; import { Injectable } from '@nestjs/common'; import { Regency } from '@prisma/client'; -import { RegencyWithParent, RegencyFindQueries } from './regency.dto'; +import { RegencyFindQueries, RegencyWithParent } from './regency.dto'; @Injectable() export class RegencyService { diff --git a/src/village/village.controller.ts b/src/village/village.controller.ts index 565bbc1..3d9c83c 100644 --- a/src/village/village.controller.ts +++ b/src/village/village.controller.ts @@ -1,4 +1,6 @@ import { ApiDataResponse } from '@/common/decorator/api-data-response.decorator'; +import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; +import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; import { Controller, Get, @@ -19,8 +21,6 @@ import { VillageWithParent, } from './village.dto'; import { VillageService } from './village.service'; -import { ApiPaginatedResponse } from '@/common/decorator/api-paginated-response.decorator'; -import { PaginatedReturn } from '@/common/interceptor/paginate.interceptor'; @Controller('villages') export class VillageController { diff --git a/src/village/village.service.spec.ts b/src/village/village.service.spec.ts index 2e061f8..9bfd2f3 100644 --- a/src/village/village.service.spec.ts +++ b/src/village/village.service.spec.ts @@ -1,16 +1,16 @@ -import { getDBProviderFeatures } from '@/common/utils/db'; -import { PrismaService } from '@/prisma/prisma.service'; -import { SortOrder } from '@/sort/sort.dto'; -import { Test } from '@nestjs/testing'; -import { District, Province, Regency, Village } from '@prisma/client'; -import { VillageService } from './village.service'; -import { mockPrismaService } from '@/prisma/__mocks__/prisma.service'; import { getDistricts, getProvinces, getRegencies, getVillages, } from '@/common/utils/data'; +import { getDBProviderFeatures } from '@/common/utils/db'; +import { mockPrismaService } from '@/prisma/__mocks__/prisma.service'; +import { PrismaService } from '@/prisma/prisma.service'; +import { SortOrder } from '@/sort/sort.dto'; +import { Test } from '@nestjs/testing'; +import { District, Province, Regency, Village } from '@prisma/client'; +import { VillageService } from './village.service'; describe('VillageService', () => { let villages: Village[]; diff --git a/test/district.e2e-spec.ts b/test/district.e2e-spec.ts index 97b0218..2d7c94b 100644 --- a/test/district.e2e-spec.ts +++ b/test/district.e2e-spec.ts @@ -22,7 +22,7 @@ describe('District (e2e)', () => { it('should return districts', async () => { const districts = await tester.expectData(baseUrl); - districts.forEach((district) => { + for (const district of districts) { expect(district).toEqual( expectIdFromMongo({ code: expect.stringMatching(districtRegex.code), @@ -30,7 +30,7 @@ describe('District (e2e)', () => { regencyCode: district.code.slice(0, 4), }), ); - }); + } }); it("should return 400 if the `name` is more than 100 chars, or contains any other symbols besides '()-./", async () => { @@ -65,7 +65,7 @@ describe('District (e2e)', () => { `${baseUrl}?name=${testName}`, ); - districts.forEach((district) => { + for (const district of districts) { expect(district).toEqual( expectIdFromMongo({ code: expect.stringMatching(districtRegex.code), @@ -73,7 +73,7 @@ describe('District (e2e)', () => { regencyCode: district.code.slice(0, 4), }), ); - }); + } }); it('should return all districts match with the `regencyCode`', async () => { @@ -82,7 +82,7 @@ describe('District (e2e)', () => { `${baseUrl}?regencyCode=${regencyCode}`, ); - districts.forEach((district) => { + for (const district of districts) { expect(district).toEqual( expectIdFromMongo({ code: expect.stringMatching(districtRegex.code), @@ -90,7 +90,7 @@ describe('District (e2e)', () => { regencyCode, }), ); - }); + } }); }); diff --git a/test/helper/data-regex.ts b/test/helper/data-regex.ts index 79ac96a..0ae915c 100644 --- a/test/helper/data-regex.ts +++ b/test/helper/data-regex.ts @@ -1,4 +1,4 @@ -import { Province, District, Island, Regency, Village } from '@prisma/client'; +import { District, Island, Province, Regency, Village } from '@prisma/client'; type DataRegex> = Partial< Record diff --git a/test/island.e2e-spec.ts b/test/island.e2e-spec.ts index 043394e..684ea54 100644 --- a/test/island.e2e-spec.ts +++ b/test/island.e2e-spec.ts @@ -18,7 +18,7 @@ describe('Island (e2e)', () => { it('should return islands', async () => { const islands = await tester.expectData(baseUrl); - islands.forEach((island) => { + for (const island of islands) { expect(island).toEqual( expectIdFromMongo({ code: expect.stringMatching(islandRegex.code), @@ -31,7 +31,7 @@ describe('Island (e2e)', () => { regencyCode: island.regencyCode ? island.code.slice(0, 4) : null, }), ); - }); + } }); it("should return 400 if the `name` is more than 100 chars, or contains any symbols except '-/", async () => { @@ -66,7 +66,7 @@ describe('Island (e2e)', () => { `${baseUrl}?name=${testName}`, ); - islands.forEach((island) => { + for (const island of islands) { expect(island).toEqual( expectIdFromMongo({ code: expect.stringMatching(islandRegex.code), @@ -79,7 +79,7 @@ describe('Island (e2e)', () => { regencyCode: island.regencyCode ? island.code.slice(0, 4) : null, }), ); - }); + } }); it('should return all islands match with the `regencyCode`', async () => { @@ -88,7 +88,7 @@ describe('Island (e2e)', () => { `${baseUrl}?regencyCode=${testRegencyCode}`, ); - islands.forEach((island) => { + for (const island of islands) { expect(island).toEqual( expectIdFromMongo({ code: expect.stringMatching(islandRegex.code), @@ -101,7 +101,7 @@ describe('Island (e2e)', () => { regencyCode: testRegencyCode, }), ); - }); + } }); it('should return all islands that does not belong to any regency', async () => { @@ -109,7 +109,7 @@ describe('Island (e2e)', () => { `${baseUrl}?regencyCode`, ); - islands.forEach((island) => { + for (const island of islands) { expect(island).toEqual( expectIdFromMongo({ code: expect.stringMatching(islandRegex.code), @@ -122,7 +122,7 @@ describe('Island (e2e)', () => { regencyCode: null, }), ); - }); + } }); }); diff --git a/test/province.e2e-spec.ts b/test/province.e2e-spec.ts index 6e9fd37..41dbadd 100644 --- a/test/province.e2e-spec.ts +++ b/test/province.e2e-spec.ts @@ -25,14 +25,14 @@ describe('Province (e2e)', () => { it('should return all provinces', async () => { const provinces = await tester.expectData(baseUrl); - provinces.forEach((province) => { + for (const province of provinces) { expect(province).toEqual( expectIdFromMongo({ code: expect.stringMatching(provinceRegex.code), name: expect.stringMatching(provinceRegex.name), }), ); - }); + } }); }); @@ -59,14 +59,14 @@ describe('Province (e2e)', () => { `${baseUrl}?name=${testName}`, ); - provinces.forEach((province) => { + for (const province of provinces) { expect(province).toEqual( expectIdFromMongo({ code: expect.stringMatching(provinceRegex.code), name: expect.stringMatching(new RegExp(testName, 'i')), }), ); - }); + } }); }); diff --git a/test/regency.e2e-spec.ts b/test/regency.e2e-spec.ts index 7cf2e08..ebfe7dd 100644 --- a/test/regency.e2e-spec.ts +++ b/test/regency.e2e-spec.ts @@ -18,7 +18,7 @@ describe('Regency (e2e)', () => { it('should return regencies', async () => { const regencies = await tester.expectData(baseUrl); - regencies.forEach((regency) => { + for (const regency of regencies) { expect(regency).toEqual( expectIdFromMongo({ code: expect.stringMatching(regencyRegex.code), @@ -26,7 +26,7 @@ describe('Regency (e2e)', () => { provinceCode: expect.stringMatching(regencyRegex.provinceCode), }), ); - }); + } }); it('should return 400 if the `name` is more than 100 chars, or contains any symbols', async () => { @@ -58,7 +58,7 @@ describe('Regency (e2e)', () => { `${baseUrl}?name=${testName}`, ); - regencies.forEach((regency) => { + for (const regency of regencies) { expect(regency).toEqual( expectIdFromMongo({ code: expect.stringMatching(regencyRegex.code), @@ -66,7 +66,7 @@ describe('Regency (e2e)', () => { provinceCode: expect.stringMatching(regencyRegex.provinceCode), }), ); - }); + } }); }); diff --git a/test/village.e2e-spec.ts b/test/village.e2e-spec.ts index cfc053c..e4556c5 100644 --- a/test/village.e2e-spec.ts +++ b/test/village.e2e-spec.ts @@ -23,7 +23,7 @@ describe('Village (e2e)', () => { it('should return villages', async () => { const villages = await tester.expectData(baseUrl); - villages.forEach((village) => { + for (const village of villages) { expect(village).toEqual( expectIdFromMongo({ code: expect.stringMatching(villageRegex.code), @@ -31,7 +31,7 @@ describe('Village (e2e)', () => { districtCode: village.code.slice(0, 6), }), ); - }); + } }); it('should return 400 if the `name` more than 100 chars, or contains any other symbols besides \'()-./"*', async () => { @@ -66,7 +66,7 @@ describe('Village (e2e)', () => { `${baseUrl}?name=${testName}`, ); - villages.forEach((village) => { + for (const village of villages) { expect(village).toEqual( expectIdFromMongo({ code: expect.stringMatching(villageRegex.code), @@ -74,7 +74,7 @@ describe('Village (e2e)', () => { districtCode: village.code.slice(0, 6), }), ); - }); + } }); it('should return all villages match with the `districtCode`', async () => { @@ -83,7 +83,7 @@ describe('Village (e2e)', () => { `${baseUrl}?districtCode=${districtCode}`, ); - villages.forEach((village) => { + for (const village of villages) { expect(village).toEqual( expectIdFromMongo({ code: expect.stringMatching(villageRegex.code), @@ -91,7 +91,7 @@ describe('Village (e2e)', () => { districtCode, }), ); - }); + } }); }); diff --git a/vitest.config.e2e.mts b/vitest.config.e2e.mts index f890dd8..5ad784e 100644 --- a/vitest.config.e2e.mts +++ b/vitest.config.e2e.mts @@ -1,6 +1,6 @@ +import path from 'node:path'; import swc from 'unplugin-swc'; import { defineConfig } from 'vitest/config'; -import path from 'node:path'; export default defineConfig({ test: { diff --git a/vitest.config.mts b/vitest.config.mts index 1d7ccca..510dca0 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -1,6 +1,6 @@ +import path from 'node:path'; import swc from 'unplugin-swc'; import { defineConfig } from 'vitest/config'; -import path from 'node:path'; export default defineConfig({ test: {