Skip to content

Commit

Permalink
Add blocked customer controllers for create, destroy, list, and range…
Browse files Browse the repository at this point in the history
… operations
  • Loading branch information
jamalsoueidan committed Mar 5, 2024
1 parent a021fac commit 885effa
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
29 changes: 29 additions & 0 deletions src/functions/customer/controllers/blocked/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { z } from "zod";
import { BlockDateZodSchema } from "~/functions/blocked/blocked.types";
import { _ } from "~/library/handler";
import { CustomerBlockedServiceCreate } from "../../services/blocked/create";
import { CustomerServiceUpdate } from "../../services/customer";

export type CustomerControllerCreateRequest = {
query: z.infer<typeof CustomerBlockedControllerQuerySchema>;
body: z.infer<typeof CustomerBlockedControllerCreateSchema>;
};

export const CustomerBlockedControllerQuerySchema = BlockDateZodSchema.pick({
customerId: true,
}).strip();

export const CustomerBlockedControllerCreateSchema = BlockDateZodSchema.omit({
customerId: true,
}).strip();

export type CustomerBlockedControllerCreateResponse = Awaited<
ReturnType<typeof CustomerServiceUpdate>
>;

export const CustomerBlockedControllerCreate = _(
({ query, body }: CustomerControllerCreateRequest) => {
const validateBody = CustomerBlockedControllerCreateSchema.parse(body);
return CustomerBlockedServiceCreate({ ...query, ...validateBody });
}
);
25 changes: 25 additions & 0 deletions src/functions/customer/controllers/blocked/destroy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { z } from "zod";
import { _ } from "~/library/handler";
import { NumberOrStringType, StringOrObjectIdType } from "~/library/zod";
import { CustomerBlockedServiceDestroy } from "../../services/blocked/destroy";
import { CustomerServiceUpdate } from "../../services/customer";

export type CustomerBlockedControllerDestroyRequest = {
query: z.infer<typeof CustomerBlockedControllerDestroySchema>;
};

export const CustomerBlockedControllerDestroySchema = z.object({
customerId: NumberOrStringType,
blockedId: StringOrObjectIdType,
});

export type CustomerBlockedControllerCreateResponse = Awaited<
ReturnType<typeof CustomerServiceUpdate>
>;

export const CustomerBlockedControllerCreate = _(
({ query }: CustomerBlockedControllerDestroyRequest) => {
const validateBody = CustomerBlockedControllerDestroySchema.parse(query);
return CustomerBlockedServiceDestroy(query);
}
);
26 changes: 26 additions & 0 deletions src/functions/customer/controllers/blocked/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { z } from "zod";
import { CustomerLocationServiceGetAll } from "~/functions/customer/services/location";
import { _ } from "~/library/handler";
import { NumberOrStringType, StringOrObjectIdType } from "~/library/zod";
import { CustomerBlockedServiceList } from "../../services/blocked/list";

export type CustomerBlockedControllerListRequest = {
query: z.infer<typeof CustomerBlockedControllerListSchema>;
};

export const CustomerBlockedControllerListSchema = z.object({
customerId: NumberOrStringType,
limit: NumberOrStringType,
nextCursor: StringOrObjectIdType,
});

export type CustomerBlockedControllerListResponse = Awaited<
ReturnType<typeof CustomerLocationServiceGetAll>
>;

export const CustomerBlockedControllerList = _(
({ query }: CustomerBlockedControllerListRequest) => {
const validateData = CustomerBlockedControllerListSchema.parse(query);
return CustomerBlockedServiceList(validateData);
}
);
26 changes: 26 additions & 0 deletions src/functions/customer/controllers/blocked/range.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { z } from "zod";
import { CustomerLocationServiceGetAll } from "~/functions/customer/services/location";
import { _ } from "~/library/handler";
import { NumberOrStringType, StringOrObjectIdType } from "~/library/zod";
import { CustomerBlockedServiceList } from "../../services/blocked/list";

export type CustomerBlockedControllerRangeRequest = {
query: z.infer<typeof CustomerBlockedControllerRangeQuerySchema>;
};

export const CustomerBlockedControllerRangeQuerySchema = z.object({
customerId: NumberOrStringType,
limit: NumberOrStringType,
nextCursor: StringOrObjectIdType,
});

export type CustomerBlockedControllerRangeQueryResponse = Awaited<
ReturnType<typeof CustomerLocationServiceGetAll>
>;

export const CustomerBlockedControllerRange = _(
({ query }: CustomerBlockedControllerRangeRequest) => {
const validateData = CustomerBlockedControllerRangeQuerySchema.parse(query);
return CustomerBlockedServiceList(validateData);
}
);
7 changes: 4 additions & 3 deletions src/functions/customer/controllers/location/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { LocationZodSchema } from "~/functions/location/location.types";
import { _ } from "~/library/handler";

export type CustomerLocationControllerGetAllRequest = {
query: z.infer<typeof LocationServiceGetAllQuerySchema>;
query: z.infer<typeof CustomerLocationControllerGetAllQuerySchema>;
};

export const LocationServiceGetAllQuerySchema = z.object({
export const CustomerLocationControllerGetAllQuerySchema = z.object({
customerId: LocationZodSchema.shape.customerId,
});

Expand All @@ -17,7 +17,8 @@ export type CustomerLocationControllerGetAllResponse = Awaited<

export const CustomerLocationControllerGetAll = _(
({ query }: CustomerLocationControllerGetAllRequest) => {
const validateData = LocationServiceGetAllQuerySchema.parse(query);
const validateData =
CustomerLocationControllerGetAllQuerySchema.parse(query);
return CustomerLocationServiceGetAll(validateData);
}
);

0 comments on commit 885effa

Please sign in to comment.