Skip to content

Commit 550b0d1

Browse files
authored
Merge branch 'development' into fix/th-125-fix-header
2 parents d16d006 + ee91c1f commit 550b0d1

File tree

153 files changed

+4386
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+4386
-309
lines changed

backend/src/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { type UserEntityObjectWithGroupT } from './packages/users/users.js';
33

44
declare module 'fastify' {
55
interface FastifyInstance {
6+
[AuthStrategy.INJECT_USER]: FastifyAuthFunction;
67
[AuthStrategy.VERIFY_JWT]: FastifyAuthFunction;
8+
[AuthStrategy.VERIFY_BUSINESS_GROUP]: FastifyAuthFunction;
9+
[AuthStrategy.VERIFY_DRIVER_GROUP]: FastifyAuthFunction;
710
}
811

912
interface FastifyRequest {

backend/src/libs/exceptions/database/database-connection.exception.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
type Constructor = {
2-
message: string;
3-
cause?: unknown;
4-
};
1+
import { type Constructor } from '~/libs/types/types.js';
52

63
class DatabaseConnectionError extends Error {
74
public constructor({ message, cause }: Constructor) {

backend/src/libs/packages/controller/controller.package.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { type ILogger } from '~/libs/packages/logger/logger.js';
22
import { type ServerAppRouteParameters } from '~/libs/packages/server-application/server-application.js';
3+
import { type ValueOf } from '~/libs/types/types.js';
4+
import { type AuthStrategy } from '~/packages/auth/auth.js';
35

46
import { type IController } from './libs/interfaces/interface.js';
57
import {
@@ -8,24 +10,37 @@ import {
810
type ControllerRouteParameters,
911
} from './libs/types/types.js';
1012

13+
type DefaultStrategies =
14+
| ValueOf<typeof AuthStrategy>
15+
| ValueOf<typeof AuthStrategy>[]
16+
| undefined;
17+
1118
class Controller implements IController {
1219
private logger: ILogger;
1320

1421
private apiUrl: string;
1522

1623
public routes: ServerAppRouteParameters[];
1724

18-
public constructor(logger: ILogger, apiPath: string) {
25+
public defaultStrategies: DefaultStrategies;
26+
27+
public constructor(
28+
logger: ILogger,
29+
apiPath: string,
30+
strategies?: DefaultStrategies,
31+
) {
1932
this.logger = logger;
2033
this.apiUrl = apiPath;
2134
this.routes = [];
35+
this.defaultStrategies = strategies;
2236
}
2337

2438
public addRoute(options: ControllerRouteParameters): void {
2539
const { handler, path } = options;
2640
const fullPath = this.apiUrl + path;
2741

2842
this.routes.push({
43+
authStrategy: this.defaultStrategies,
2944
...options,
3045
path: fullPath,
3146
handler: (request, reply) => this.mapHandler(handler, request, reply),

backend/src/libs/packages/controller/libs/types/auth-strategy-handler.type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { type AuthStrategy } from '~/packages/auth/auth.js';
66

77
type AuthStrategyHandler =
88
| ValueOf<typeof AuthStrategy>
9+
| ValueOf<typeof AuthStrategy>[]
910
| ((
1011
fastify: FastifyInstance,
1112
) =>
1213
| FastifyAuthFunction[]
13-
| (FastifyAuthFunction | FastifyAuthFunction[])[]);
14+
| (FastifyAuthFunction | FastifyAuthFunction[])[])
15+
| null;
1416

1517
export { type AuthStrategyHandler };
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TABLE IF NOT EXISTS
2+
"driver_details" (
3+
"id" serial PRIMARY KEY NOT NULL,
4+
"driver_license_number" varchar NOT NULL,
5+
"user_id" integer NOT NULL,
6+
"business_id" integer NOT NULL,
7+
"created_at" timestamp DEFAULT now() NOT NULL,
8+
"updated_at" timestamp DEFAULT now() NOT NULL,
9+
CONSTRAINT "driver_details_driver_license_number_unique" UNIQUE ("driver_license_number")
10+
);
11+
12+
--> statement-breakpoint
13+
DO $$ BEGIN
14+
ALTER TABLE "driver_details" ADD CONSTRAINT "driver_details_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
15+
EXCEPTION
16+
WHEN duplicate_object THEN null;
17+
END $$;
18+
19+
--> statement-breakpoint
20+
DO $$ BEGIN
21+
ALTER TABLE "driver_details" ADD CONSTRAINT "driver_details_business_id_business_details_id_fk" FOREIGN KEY ("business_id") REFERENCES "business_details"("id") ON DELETE no action ON UPDATE no action;
22+
EXCEPTION
23+
WHEN duplicate_object THEN null;
24+
END $$;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
CREATE TABLE IF NOT EXISTS
2+
"trucks" (
3+
"id" serial PRIMARY KEY NOT NULL,
4+
"created_at" timestamp DEFAULT now() NOT NULL,
5+
"updated_at" timestamp DEFAULT now() NOT NULL,
6+
"manufacturer" varchar NOT NULL,
7+
"capacity" integer NOT NULL,
8+
"price_per_km" real NOT NULL,
9+
"license_plate_number" varchar NOT NULL,
10+
"year" integer NOT NULL,
11+
"tow_type" varchar NOT NULL
12+
);
13+
14+
--> statement-breakpoint
15+
CREATE TABLE IF NOT EXISTS
16+
"users_trucks" (
17+
"user_id" integer NOT NULL,
18+
"truck_id" integer NOT NULL,
19+
CONSTRAINT users_trucks_user_id_truck_id PRIMARY KEY ("user_id", "truck_id")
20+
);
21+
22+
--> statement-breakpoint
23+
CREATE UNIQUE INDEX IF NOT EXISTS "trucks_license_plate_number_idx" ON "trucks" ("license_plate_number");
24+
25+
--> statement-breakpoint
26+
DO $$ BEGIN
27+
ALTER TABLE "users_trucks" ADD CONSTRAINT "users_trucks_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE no action;
28+
EXCEPTION
29+
WHEN duplicate_object THEN null;
30+
END $$;
31+
32+
--> statement-breakpoint
33+
DO $$ BEGIN
34+
ALTER TABLE "users_trucks" ADD CONSTRAINT "users_trucks_truck_id_trucks_id_fk" FOREIGN KEY ("truck_id") REFERENCES "trucks"("id") ON DELETE cascade ON UPDATE no action;
35+
EXCEPTION
36+
WHEN duplicate_object THEN null;
37+
END $$;

0 commit comments

Comments
 (0)