Skip to content

Commit

Permalink
refactor(be): absolute import paths
Browse files Browse the repository at this point in the history
  • Loading branch information
krystxf committed Oct 4, 2024
1 parent de4bc5f commit cac96ca
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 44 deletions.
12 changes: 12 additions & 0 deletions backend-nest/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,17 @@ module.exports = {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-restricted-imports": [
"error",
{
patterns: [
{
group: [".*"],
message:
"Relative imports are not allowed, use absolute import instead.",
},
],
},
],
},
};
20 changes: 10 additions & 10 deletions backend-nest/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Module } from "@nestjs/common";
import { CacheInterceptor, CacheModule } from "@nestjs/cache-manager";
import { ConfigModule } from "@nestjs/config";
import { TTL_DEFAULT } from "./constants/constants";
import { TTL_DEFAULT } from "src/constants/constants";
import { ScheduleModule } from "@nestjs/schedule";
import { PrismaService } from "./database/prisma.service";
import { PlatformController } from "./modules/platform/platform.controller";
import { PrismaService } from "src/database/prisma.service";
import { PlatformController } from "src/modules/platform/platform.controller";
import { APP_INTERCEPTOR } from "@nestjs/core";
import { PlatformService } from "./modules/platform/platform.service";
import { DepartureController } from "./modules/departure/departure.controller";
import { DepartureService } from "./modules/departure/departure.service";
import { StopService } from "./modules/stop/stop.service";
import { StopController } from "./modules/stop/stop.controller";
import { ImportController } from "./modules/import/import.controller";
import { ImportService } from "./modules/import/import.service";
import { PlatformService } from "src/modules/platform/platform.service";
import { DepartureController } from "src/modules/departure/departure.controller";
import { DepartureService } from "src/modules/departure/departure.service";
import { StopService } from "src/modules/stop/stop.service";
import { StopController } from "src/modules/stop/stop.controller";
import { ImportController } from "src/modules/import/import.controller";
import { ImportService } from "src/modules/import/import.service";

@Module({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion backend-nest/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { GOLEMIO_API, TTL_DEFAULT } from "./constants";
export { GOLEMIO_API, TTL_DEFAULT } from "src/constants/constants";
4 changes: 2 additions & 2 deletions backend-nest/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { AppModule } from "src/app.module";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
import {
SWAGGER_DESCRIPTION,
SWAGGER_JSON_URL,
SWAGGER_TITLE,
SWAGGER_API_ROOT,
SWAGGER_VERSION,
} from "./swagger/swagger.const";
} from "src/swagger/swagger.const";

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand Down
4 changes: 2 additions & 2 deletions backend-nest/src/modules/departure/departure.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
HttpStatus,
Query,
} from "@nestjs/common";
import { DepartureService } from "./departure.service";
import { DepartureService } from "src/modules/departure/departure.service";
import { toArray } from "src/utils/array.utils";
import { z } from "zod";
import {
departureSchema,
type DepartureSchema,
} from "./schema/departure.schema";
} from "src/modules/departure/schema/departure.schema";
import { CacheTTL } from "@nestjs/cache-manager";
import { QUERY_IDS_COUNT_MAX } from "src/constants/constants";
import { ApiTags } from "@nestjs/swagger";
Expand Down
4 changes: 2 additions & 2 deletions backend-nest/src/modules/departure/departure.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpException, HttpStatus, Injectable } from "@nestjs/common";
import { GOLEMIO_API } from "src/constants";
import type { DepartureSchema } from "./schema/departure.schema";
import { departureBoardsSchema } from "./schema/departure-boards.schema";
import type { DepartureSchema } from "src/modules/departure/schema/departure.schema";
import { departureBoardsSchema } from "src/modules/departure/schema/departure-boards.schema";
import { getDelayInSeconds } from "src/utils/delay";
import { PrismaService } from "src/database/prisma.service";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { infoTextSchema } from "./info-text.schema";
import { infoTextSchema } from "src/modules/departure/schema/info-text.schema";
import { timestampSchema } from "src/schema/timestamp.schema";
import { delaySchema } from "src/schema/delay.schema";

Expand Down
2 changes: 1 addition & 1 deletion backend-nest/src/modules/import/import.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller, OnModuleInit } from "@nestjs/common";
import { Cron, CronExpression } from "@nestjs/schedule";
import { ImportService } from "./import.service";
import { ImportService } from "src/modules/import/import.service";

@Controller("import")
export class ImportController implements OnModuleInit {
Expand Down
4 changes: 2 additions & 2 deletions backend-nest/src/modules/import/import.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from "@nestjs/common";
import { ImportService } from "./import.service";
import { ImportController } from "./import.controller";
import { ImportService } from "src/modules/import/import.service";
import { ImportController } from "src/modules/import/import.controller";

@Module({
controllers: [ImportController],
Expand Down
7 changes: 5 additions & 2 deletions backend-nest/src/modules/import/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { CACHE_MANAGER } from "@nestjs/cache-manager";
import {
pidPlatformsSchema,
type PidPlatformsSchema,
} from "./schema/pid-platforms.schema";
import { pidStopsSchema, type PidStopsSchema } from "./schema/pid-stops.schema";
} from "src/modules/import/schema/pid-platforms.schema";
import {
pidStopsSchema,
type PidStopsSchema,
} from "src/modules/import/schema/pid-stops.schema";
import { metroLine } from "src/enums/metro.enum";

@Injectable()
Expand Down
34 changes: 22 additions & 12 deletions backend-nest/src/modules/platform/platform.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import {
Query,
} from "@nestjs/common";
import { CacheTTL } from "@nestjs/cache-manager";
import { PlatformService } from "./platform.service";
import { platformSchema, type PlatformSchema } from "./schema/platform.schema";
import { boundingBoxSchema } from "../../schema/bounding-box.schema";
import { PlatformService } from "src/modules/platform/platform.service";
import {
platformSchema,
type PlatformSchema,
} from "src/modules/platform/schema/platform.schema";
import { boundingBoxSchema } from "src/schema/bounding-box.schema";
import { z } from "zod";
import {
platformWithDistanceSchema,
PlatformWithDistanceSchema,
} from "./schema/platform-with-distance.schema";
} from "src/modules/platform/schema/platform-with-distance.schema";
import { ApiQuery, ApiTags } from "@nestjs/swagger";
import {
boundingBoxQuery,
Expand All @@ -35,14 +38,21 @@ export class PlatformController {
summary: "List of all platforms",
})
@ApiQuery(metroOnlyQuery)
async getAllPlatforms(
@Query("metroOnly")
metroOnlyQuery: unknown,
): Promise<PlatformSchema[]> {
const metroOnly: boolean = metroOnlyQuery === "true";
const platforms = await this.platformService.getAllPlatforms({
metroOnly,
async getAllPlatforms(@Query() query): Promise<PlatformSchema[]> {
const schema = z.object({
metroOnly: metroOnlySchema,
});
const parsed = schema.safeParse(query);
if (!parsed.success) {
throw new HttpException(
parsed.error.format(),
HttpStatus.BAD_REQUEST,
);
}

const platforms = await this.platformService.getAllPlatforms(
parsed.data,
);

return platformSchema.array().parse(platforms);
}
Expand Down Expand Up @@ -83,7 +93,7 @@ Sort platforms by distance to a given location. Location may be saved in logs.

if (!parsed.success) {
throw new HttpException(
"Invalid query params",
parsed.error.format(),
HttpStatus.BAD_REQUEST,
);
}
Expand Down
6 changes: 3 additions & 3 deletions backend-nest/src/modules/platform/platform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Inject, Injectable } from "@nestjs/common";
import { PrismaService } from "src/database/prisma.service";

import { CACHE_MANAGER } from "@nestjs/cache-manager";
import { PlatformSchema } from "./schema/platform.schema";
import type { BoundingBox } from "../../schema/bounding-box.schema";
import { PlatformSchema } from "src/modules/platform/schema/platform.schema";
import type { BoundingBox } from "src/schema/bounding-box.schema";
import { minMax } from "src/utils/math";
import { Prisma } from "@prisma/client";
import { PlatformWithDistanceSchema } from "./schema/platform-with-distance.schema";
import { PlatformWithDistanceSchema } from "src/modules/platform/schema/platform-with-distance.schema";

export const platformSelect = {
id: true,
Expand Down
2 changes: 1 addition & 1 deletion backend-nest/src/modules/stop/stop.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CacheTTL } from "@nestjs/cache-manager";
import { Controller, Get, Query } from "@nestjs/common";
import { StopService } from "./stop.service";
import { StopService } from "src/modules/stop/stop.service";
import { ApiQuery, ApiTags } from "@nestjs/swagger";
import { metroOnlyQuery } from "src/swagger/query.swagger";

Expand Down
4 changes: 2 additions & 2 deletions backend-nest/src/modules/stop/stop.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from "@nestjs/common";

import { StopController } from "./stop.controller";
import { StopService } from "./stop.service";
import { StopController } from "src/modules/stop/stop.controller";
import { StopService } from "src/modules/stop/stop.service";

@Module({
controllers: [StopController],
Expand Down
2 changes: 1 addition & 1 deletion backend-nest/src/modules/stop/stop.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { PrismaService } from "src/database/prisma.service";
import { platformSelect } from "../platform/platform.service";
import { platformSelect } from "src/modules/platform/platform.service";

export const getStopsSelect = ({ metroOnly }: { metroOnly: boolean }) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion backend-nest/src/utils/delay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { delaySchema, type DelaySchema } from "../schema/delay.schema";
import { delaySchema, type DelaySchema } from "src/schema/delay.schema";

export const getDelayInSeconds = (delay: DelaySchema): number => {
const parsed = delaySchema.safeParse(delay);
Expand Down
2 changes: 1 addition & 1 deletion backend-nest/src/utils/math.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { min, max, minMax } from "./math";
import { min, max, minMax } from "src/utils/math";

describe("min", () => {
it("should support single value", () => {
Expand Down

0 comments on commit cac96ca

Please sign in to comment.