Skip to content

Commit d0f3edd

Browse files
albsbzalbsbz
andauthored
th-110: Order schema (#150)
* th-110: + order repository * th-110: * merge conflicts * th-110: + added combine filters helper * th-110: * lint problems * th-110: - orderedStatusT * th-110: * orders types usage * th-110: * merge conflicts * th-110: + swagger for order delete * th-110: + swagger for order create * th-110: + swagger for order update * th-110: * error handling * th-110: * with inject user strategy * th-110: * repository methods usage * th-110: * fix order schemes * th-110: * schema enum export * th-110: * linting * th-110: * relations * th-110: + driver service usage * th-110: * lint * th-110: * types usage * th-110: * order get parameter schema * th-110: * generated schema * th-110: + cars qty * th-110: * order controller * th-110: * order controller * th-110: * remove signup mock * th-110: * order controller * th-110: * imports * th-110: + drivers details db relation * th-110: + add driver to findById response * th-110: + add driver to findById response * th-110: + add driver to findById response * th-110: + add order with driver entity * th-110: * order-with-driver entity * th-110: * move logic from order controller to service * th-110: - redundant params in order * th-110: * order service --------- Co-authored-by: albsbz <[email protected]>
1 parent 36ae799 commit d0f3edd

Some content is hidden

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

50 files changed

+2084
-39
lines changed

backend/src/libs/exceptions/not-found-error/not-found-error.exception.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import { AppErrorMessage, HttpCode } from '~/libs/enums/enums.js';
2-
import { type ErrorConstructor, type ValueOf } from '~/libs/types/types.js';
1+
import { AppErrorMessage, HttpCode } from '../../enums/enums.js';
2+
import { HttpError } from '../exceptions.js';
33

4-
import { ApplicationError } from '../exceptions.js';
4+
type Constructor = {
5+
message?: string;
6+
cause?: unknown;
7+
};
58

6-
type NotFoundErrorConstructor = Partial<ErrorConstructor>;
7-
8-
class NotFoundError extends ApplicationError {
9-
public status: ValueOf<typeof HttpCode>;
10-
11-
public constructor({ message, cause }: NotFoundErrorConstructor) {
9+
class NotFoundError extends HttpError {
10+
public constructor({ message, cause }: Constructor) {
1211
super({
1312
message: message ?? AppErrorMessage.ENTITY_NOT_FOUND,
13+
status: HttpCode.NOT_FOUND,
1414
cause,
1515
});
16-
17-
this.status = HttpCode.NOT_FOUND;
1816
}
1917
}
2018

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
import { type UserEntityObjectWithGroupT } from '~/packages/users/users.js';
1+
import { type UserEntityObjectWithGroupT } from '~/packages/users/libs/types/types.js';
22

3-
type DefaultApiHandlerOptions = {
4-
body?: unknown;
5-
query?: unknown;
6-
params?: unknown;
7-
user?: UserEntityObjectWithGroupT;
8-
};
3+
import { type DefaultApiHandlerOptions } from './default-api-handler-options.type.js';
94

105
type ApiHandlerOptions<
116
T extends DefaultApiHandlerOptions = DefaultApiHandlerOptions,
127
> = {
138
body: T['body'];
149
query: T['query'];
1510
params: T['params'];
16-
user: T['user'] extends unknown
17-
? NonNullable<DefaultApiHandlerOptions['user']>
18-
: T['user'];
11+
user: undefined extends T['user'] ? UserEntityObjectWithGroupT : T['user'];
1912
};
2013

2114
export { type ApiHandlerOptions };

backend/src/libs/packages/controller/libs/types/controller-route-parameters.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type ControllerRouteParameters = {
1212
validation?: {
1313
body?: ValidationSchema;
1414
params?: ValidationSchema;
15+
query?: ValidationSchema;
1516
};
1617
};
1718

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type DefaultApiHandlerOptions = {
2+
body?: unknown;
3+
query?: unknown;
4+
params?: unknown;
5+
user?: unknown;
6+
};
7+
8+
export { type DefaultApiHandlerOptions };
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
DO $$ BEGIN
2+
CREATE TYPE "order_status" AS ENUM('pending', 'confirmed', 'canceled', 'done');
3+
EXCEPTION
4+
WHEN duplicate_object THEN null;
5+
END $$;
6+
7+
--> statement-breakpoint
8+
CREATE TABLE IF NOT EXISTS
9+
"orders" (
10+
"id" serial PRIMARY KEY NOT NULL,
11+
"price" integer NOT NULL,
12+
"scheduled_time" timestamp NOT NULL,
13+
"start_point" varchar NOT NULL,
14+
"end_point" varchar NOT NULL,
15+
"status" "order_status" NOT NULL,
16+
"user_id" integer,
17+
"business_id" integer,
18+
"driver_id" integer,
19+
"cars_qty" integer DEFAULT 1 NOT NULL,
20+
"customer_name" varchar,
21+
"customer_phone" varchar,
22+
"created_at" timestamp DEFAULT now() NOT NULL,
23+
"updated_at" timestamp DEFAULT now() NOT NULL
24+
);
25+
26+
--> statement-breakpoint
27+
DO $$ BEGIN
28+
ALTER TABLE "orders" ADD CONSTRAINT "orders_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
29+
EXCEPTION
30+
WHEN duplicate_object THEN null;
31+
END $$;
32+
33+
--> statement-breakpoint
34+
DO $$ BEGIN
35+
ALTER TABLE "orders" ADD CONSTRAINT "orders_business_id_business_details_id_fk" FOREIGN KEY ("business_id") REFERENCES "business_details"("id") ON DELETE no action ON UPDATE no action;
36+
EXCEPTION
37+
WHEN duplicate_object THEN null;
38+
END $$;
39+
40+
--> statement-breakpoint
41+
DO $$ BEGIN
42+
ALTER TABLE "orders" ADD CONSTRAINT "orders_driver_id_driver_details_id_fk" FOREIGN KEY ("driver_id") REFERENCES "driver_details"("id") ON DELETE no action ON UPDATE no action;
43+
EXCEPTION
44+
WHEN duplicate_object THEN null;
45+
END $$;

0 commit comments

Comments
 (0)