refactor: migrate from most of the custom hooks into the api.ts

This commit is contained in:
Nathnael
2026-06-22 13:46:38 +00:00
parent c6bc636495
commit 2700a3edec
50 changed files with 1165 additions and 1249 deletions

View File

@@ -42,7 +42,68 @@ import {
type Cargo,
type DeliverCargoPayload,
} from "./cargoService";
import { containerService, type Container } from "./containerService";
import { containerTypesService } from "./container-types.service";
import {
wagonService,
type Wagon,
type WagonListFilters,
} from "./wagon.service";
import { wagonTypesService, type WagonType } from "./wagon-types.service";
import { trainService, type Train } from "./trains.service";
import {
locomotivesService,
type Locomotive,
type SaveLocomotivePayload,
} from "./locomotives.service";
import { cargoTypesService } from "./cargo-types.service";
import {
fleetService,
type FleetListFilters,
type FleetRecord,
} from "./fleet/fleet.service";
import type { FleetResourceSlug } from "@/pages/fleet/config/resources";
import {
paymentsService,
type PaginatedPayments,
type PaymentListFilter,
type PaymentSummary,
} from "./payments.service";
import {
signaturesService,
type SavedSignature,
type SaveSignaturePayload,
} from "./signatures.service";
import { warehouseService } from "./warehouse.service";
import { trainSchedulingService } from "./trainScheduling.service";
import {
routesService,
type RouteRecord,
type SaveRoutePayload,
type YardRef,
} from "./routes.service";
import type {
AssignBookingsPayload,
BatchBoardSchedule,
BatchBoardScheduleDetail,
BookableSchedule,
CompositionRemovalEntry,
CreateTrainSchedulePayload,
EligibleContainerBookingsResponse,
FreightType,
LocomotiveRecord,
PinWagonsPayload,
RecordCheckpointPayload,
TrainScheduleDetail,
TrainScheduleFilters,
TrainScheduleListItem,
TrainSchedulePreviewPayload,
TrainSchedulePreviewResponse,
TrainTrackResponse,
UnassignedBookingsResponse,
WagonAllocationAttemptResult,
YardOption,
} from "@/types/trainScheduling";
import type {
AllocationCriteria,
AllocationPreviewResult,
@@ -104,7 +165,333 @@ const INVENTORY_INVALIDATIONS: ReadonlyArray<readonly unknown[]> = [
["warehouses"],
];
/**
* Train-scheduling mutations broadly affect the schedule board and bookings.
* The grouped hooks invalidated TRAIN_SCHEDULING.ROOT + BOOKINGS.ROOT; since
* every train-scheduling key is prefixed with `"train-scheduling"`, the two
* roots below cover all of them via React Query's prefix matching.
*/
const TRAIN_SCHEDULING_INVALIDATIONS: ReadonlyArray<readonly unknown[]> = [
QUERY_KEYS.TRAIN_SCHEDULING.ROOT,
QUERY_KEYS.BOOKINGS.ROOT,
];
export const api = {
trainScheduling: {
// ── Queries ────────────────────────────────────────────────────────────
scheduleList: endpoint<{ freightType?: FreightType }, TrainScheduleListItem[]>(
"train-scheduling",
"schedules",
({ freightType }) => trainSchedulingService.listSchedules(freightType),
() => QUERY_KEYS.TRAIN_SCHEDULING.schedules(),
),
batchBoard: endpoint<void, BatchBoardSchedule[]>(
"train-scheduling",
"batch-board",
() => trainSchedulingService.getBatchBoard(),
() => QUERY_KEYS.TRAIN_SCHEDULING.batchBoard(),
),
batchBoardDetail: endpoint<{ scheduleId: string }, BatchBoardScheduleDetail>(
"train-scheduling",
"batch-board-detail",
({ scheduleId }) => trainSchedulingService.getBatchBoardDetail(scheduleId),
({ scheduleId }) => QUERY_KEYS.TRAIN_SCHEDULING.batchBoardDetail(scheduleId),
),
scheduleDetail: endpoint<
{ id: string; freightType?: FreightType },
TrainScheduleDetail
>(
"train-scheduling",
"schedule-detail",
({ id, freightType }) =>
trainSchedulingService.getScheduleById(id, freightType),
({ id }) => QUERY_KEYS.TRAIN_SCHEDULING.scheduleById(id),
),
eligibleBookings: endpoint<
{ filters?: TrainScheduleFilters; freightType?: FreightType },
EligibleContainerBookingsResponse
>(
"train-scheduling",
"eligible-bookings",
({ filters, freightType }) =>
trainSchedulingService.getEligibleBookings(filters, freightType),
({ filters, freightType }) =>
QUERY_KEYS.TRAIN_SCHEDULING.eligible(freightType, filters),
),
availableLocomotives: endpoint<{ routeId?: string }, LocomotiveRecord[]>(
"train-scheduling",
"locomotives",
({ routeId }) => trainSchedulingService.getAvailableLocomotives(routeId),
({ routeId }) => QUERY_KEYS.TRAIN_SCHEDULING.locomotives(routeId),
),
bookableSchedules: endpoint<
{ originYardId?: string | null; destinationYardId?: string | null },
BookableSchedule[]
>(
"train-scheduling",
"bookable",
({ originYardId, destinationYardId }) =>
trainSchedulingService.getBookableSchedules(
originYardId ?? undefined,
destinationYardId ?? undefined,
),
({ originYardId, destinationYardId }) => [
...QUERY_KEYS.TRAIN_SCHEDULING.ROOT,
"bookable",
originYardId ?? "",
destinationYardId ?? "",
],
),
availableDays: endpoint<
{ originYardId?: string | null; destinationYardId?: string | null },
string[]
>(
"train-scheduling",
"available-days",
({ originYardId, destinationYardId }) =>
trainSchedulingService.getAvailableDays(
originYardId ?? undefined,
destinationYardId ?? undefined,
),
({ originYardId, destinationYardId }) => [
...QUERY_KEYS.TRAIN_SCHEDULING.ROOT,
"available-days",
originYardId ?? "",
destinationYardId ?? "",
],
),
trainTrack: endpoint<{ id: string }, TrainTrackResponse>(
"train-scheduling",
"track",
({ id }) => trainSchedulingService.getTrack(id),
({ id }) => QUERY_KEYS.TRAIN_SCHEDULING.track(id),
),
unassignedBookings: endpoint<
{ scheduleId: string },
UnassignedBookingsResponse
>(
"train-scheduling",
"unassigned-bookings",
({ scheduleId }) =>
trainSchedulingService.getUnassignedBookings(scheduleId),
({ scheduleId }) =>
QUERY_KEYS.TRAIN_SCHEDULING.unassignedBookings(scheduleId),
),
compositionRemovals: endpoint<
{ scheduleId: string },
CompositionRemovalEntry[]
>(
"train-scheduling",
"composition-removals",
({ scheduleId }) =>
trainSchedulingService.getCompositionRemovals(scheduleId),
({ scheduleId }) =>
QUERY_KEYS.TRAIN_SCHEDULING.compositionRemovals(scheduleId),
),
// ── Mutations ──────────────────────────────────────────────────────────
runAllocation: endpoint<{ scheduleId: string }, WagonAllocationAttemptResult>(
"train-scheduling",
"run-allocation",
({ scheduleId }) => trainSchedulingService.runAllocation(scheduleId),
undefined,
() => [QUERY_KEYS.TRAIN_SCHEDULING.ROOT],
),
runBatch: endpoint<string, BatchBoardScheduleDetail>(
"train-scheduling",
"run-batch",
(id) => trainSchedulingService.runBatch(id),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
setBookingWindow: endpoint<
{ id: string; status: "OPEN" | "CLOSED" },
TrainScheduleDetail
>(
"train-scheduling",
"set-booking-window",
({ id, status }) => trainSchedulingService.setBookingWindow(id, status),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
markBookingPaid: endpoint<string, void>(
"train-scheduling",
"mark-booking-paid",
(bookingId) => trainSchedulingService.markBookingPaid(bookingId),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
expireBooking: endpoint<string, void>(
"train-scheduling",
"expire-booking",
(bookingId) => trainSchedulingService.expireBooking(bookingId),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
moveBookingSchedule: endpoint<
{ bookingId: string; trainScheduleId: string },
void
>(
"train-scheduling",
"move-booking-schedule",
({ bookingId, trainScheduleId }) =>
trainSchedulingService.moveBookingSchedule(bookingId, trainScheduleId),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
createSchedule: endpoint<
{ freightType?: FreightType; payload: CreateTrainSchedulePayload },
TrainScheduleDetail
>(
"train-scheduling",
"create-schedule",
({ freightType, payload }) =>
trainSchedulingService.createSchedule(payload, freightType),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
preview: endpoint<
{ freightType?: FreightType; payload: TrainSchedulePreviewPayload },
TrainSchedulePreviewResponse
>("train-scheduling", "preview", ({ freightType, payload }) =>
trainSchedulingService.preview(payload, freightType),
),
assignBookings: endpoint<
{ id: string; freightType?: FreightType; payload: AssignBookingsPayload },
TrainScheduleDetail
>(
"train-scheduling",
"assign-bookings",
({ id, freightType, payload }) =>
trainSchedulingService.assignBookings(id, payload, freightType),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
assignUnassignedBooking: endpoint<
{ id: string; bookingId: string },
TrainScheduleDetail
>(
"train-scheduling",
"assign-unassigned-booking",
({ id, bookingId }) =>
trainSchedulingService.assignUnassignedBooking(id, bookingId),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
unassignBooking: endpoint<
{ id: string; bookingId: string },
TrainScheduleDetail
>(
"train-scheduling",
"unassign-booking",
({ id, bookingId }) =>
trainSchedulingService.unassignBooking(id, bookingId),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
pinWagons: endpoint<{ id: string; payload: PinWagonsPayload }, TrainScheduleDetail>(
"train-scheduling",
"pin-wagons",
({ id, payload }) => trainSchedulingService.pinWagons(id, payload),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
finalizeSchedule: endpoint<string, TrainScheduleDetail>(
"train-scheduling",
"finalize-schedule",
(id) => trainSchedulingService.finalizeSchedule(id),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
dispatchSchedule: endpoint<string, TrainScheduleDetail>(
"train-scheduling",
"dispatch-schedule",
(id) => trainSchedulingService.dispatchSchedule(id),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
cancelSchedule: endpoint<
{ id: string; freightType?: FreightType },
TrainScheduleDetail
>(
"train-scheduling",
"cancel-schedule",
({ id, freightType }) =>
trainSchedulingService.cancelSchedule(id, freightType ?? "CONTAINER"),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
recordCheckpoint: endpoint<
{ id: string; payload: RecordCheckpointPayload },
TrainTrackResponse
>(
"train-scheduling",
"record-checkpoint",
({ id, payload }) => trainSchedulingService.recordCheckpoint(id, payload),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
arriveSchedule: endpoint<string, TrainScheduleDetail>(
"train-scheduling",
"arrive-schedule",
(id) => trainSchedulingService.arriveSchedule(id),
undefined,
() => TRAIN_SCHEDULING_INVALIDATIONS,
),
removeWagonSlot: endpoint<
{ scheduleId: string; wagonId: string },
TrainScheduleDetail
>(
"train-scheduling",
"remove-wagon-slot",
({ scheduleId, wagonId }) =>
trainSchedulingService.removeWagonSlot(scheduleId, wagonId),
undefined,
() => [QUERY_KEYS.TRAIN_SCHEDULING.ROOT],
),
updateContainerItem: endpoint<
{ scheduleId: string; itemId: string; containerNumber: string | null },
{ id: string; containerNumber: string | null }
>(
"train-scheduling",
"update-container-item",
({ scheduleId, itemId, containerNumber }) =>
trainSchedulingService.updateContainerItem(scheduleId, itemId, {
containerNumber,
}),
undefined,
() => [QUERY_KEYS.TRAIN_SCHEDULING.ROOT],
),
},
warehouses: {
// ── Warehouses ─────────────────────────────────────────────────────────
list: endpoint<{ filter?: WarehouseFilter }, Warehouse[]>(
@@ -685,6 +1072,388 @@ export const api = {
),
},
routes: {
list: endpoint<void, RouteRecord[]>("routes", "list", () =>
routesService.getAll().then((r) => r.data),
),
yards: endpoint<void, YardRef[]>(
"routes",
"yards",
() => routesService.getYards().then((r) => r.data.data),
() => ["routes", "yards"],
),
create: endpoint<SaveRoutePayload, RouteRecord>(
"routes",
"create",
(payload) => routesService.create(payload).then((r) => r.data),
undefined,
() => [["routes"]],
),
update: endpoint<{ id: string; data: Partial<SaveRoutePayload> }, RouteRecord>(
"routes",
"update",
({ id, data }) => routesService.update(id, data).then((r) => r.data),
undefined,
() => [["routes"]],
),
deactivate: endpoint<string, void>(
"routes",
"deactivate",
(id) => routesService.deactivate(id).then(() => undefined),
undefined,
() => [["routes"]],
),
},
stations: {
list: endpoint<void, YardOption[]>(
"train-scheduling",
"stations",
() => trainSchedulingService.getStations(),
() => QUERY_KEYS.TRAIN_SCHEDULING.stations(),
),
},
containers: {
list: endpoint<void, Container[]>("containers", "list", () =>
containerService.getAll().then((r) => r.data),
),
listByWagon: endpoint<{ wagonId: string }, Container[]>(
"containers",
"listByWagon",
({ wagonId }) => containerService.getByWagon(wagonId).then((r) => r.data),
({ wagonId }) => ["containers", "wagon", wagonId],
),
getById: endpoint<{ id: string }, Container>(
"containers",
"getById",
({ id }) => containerService.getById(id).then((r) => r.data),
),
create: endpoint<Partial<Container>, Container>(
"containers",
"create",
(payload) => containerService.create(payload).then((r) => r.data),
undefined,
() => [["containers"]],
),
update: endpoint<{ id: string; data: Partial<Container> }, Container>(
"containers",
"update",
({ id, data }) => containerService.update(id, data).then((r) => r.data),
undefined,
() => [["containers"]],
),
remove: endpoint<string, void>(
"containers",
"remove",
(id) => containerService.delete(id).then(() => undefined),
undefined,
() => [["containers"]],
),
assignToWagon: endpoint<
{ containerId: string; wagonId: string; position?: number },
Container
>(
"containers",
"assignToWagon",
({ containerId, wagonId, position }) =>
containerService
.assignToWagon(containerId, wagonId, position)
.then((r) => r.data),
undefined,
() => [["containers"]],
),
unassign: endpoint<string, void>(
"containers",
"unassign",
(containerId) =>
containerService.unassign(containerId).then(() => undefined),
undefined,
() => [["containers"]],
),
},
containerTypes: {
list: endpoint<void, unknown[]>("container-types", "list", () =>
containerTypesService.getContainerTypes(),
),
},
wagons: {
list: endpoint<{ filters?: WagonListFilters }, Wagon[]>(
"wagons",
"list",
({ filters }) => wagonService.getAll(filters ?? {}).then((r) => r.data),
({ filters }) => ["wagons", "list", filters ?? {}],
),
listByTrain: endpoint<{ trainId: string }, Wagon[]>(
"wagons",
"listByTrain",
({ trainId }) => wagonService.getByTrain(trainId).then((r) => r.data),
({ trainId }) => ["wagons", "train", trainId],
),
getById: endpoint<{ id: string }, Wagon>(
"wagons",
"getById",
({ id }) => wagonService.getById(id).then((r) => r.data),
),
assignToTrain: endpoint<
{ wagonId: string; trainId: string; sequenceNumber?: number },
Wagon
>(
"wagons",
"assignToTrain",
({ wagonId, trainId, sequenceNumber }) =>
wagonService
.assignToTrain(wagonId, trainId, sequenceNumber)
.then((r) => r.data),
undefined,
() => [["wagons"]],
),
unassign: endpoint<string, void>(
"wagons",
"unassign",
(wagonId) => wagonService.unassign(wagonId).then(() => undefined),
undefined,
() => [["wagons"]],
),
reorder: endpoint<{ trainId: string; wagonIds: string[] }, Wagon[]>(
"wagons",
"reorder",
({ trainId, wagonIds }) =>
wagonService.reorder(trainId, wagonIds).then((r) => r.data),
undefined,
() => [["wagons"]],
),
create: endpoint<Partial<Wagon>, Wagon>(
"wagons",
"create",
(payload) => wagonService.create(payload).then((r) => r.data),
undefined,
() => [["wagons"]],
),
update: endpoint<{ id: string; data: Partial<Wagon> }, Wagon>(
"wagons",
"update",
({ id, data }) => wagonService.update(id, data).then((r) => r.data),
undefined,
() => [["wagons"]],
),
remove: endpoint<string, void>(
"wagons",
"remove",
(id) => wagonService.delete(id).then(() => undefined),
undefined,
() => [["wagons"]],
),
},
trains: {
list: endpoint<void, Train[]>(
"trains",
"list",
() => trainService.getAll().then((r) => r.data),
() => ["trains", "list"],
),
getById: endpoint<{ id: string }, Train>(
"trains",
"getById",
({ id }) => trainService.getById(id).then((r) => r.data),
({ id }) => ["trains", "detail", id],
),
create: endpoint<Partial<Train>, Train>(
"trains",
"create",
(payload) => trainService.create(payload).then((r) => r.data),
undefined,
() => [["trains"]],
),
update: endpoint<{ id: string; data: Partial<Train> }, Train>(
"trains",
"update",
({ id, data }) => trainService.update(id, data).then((r) => r.data),
undefined,
() => [["trains"]],
),
remove: endpoint<string, void>(
"trains",
"remove",
(id) => trainService.delete(id).then(() => undefined),
undefined,
() => [["trains"]],
),
},
locomotives: {
list: endpoint<void, Locomotive[]>(
"locomotives",
"list",
() => locomotivesService.getAll().then((r) => r.data),
() => ["locomotives"],
),
create: endpoint<Partial<SaveLocomotivePayload>, Locomotive>(
"locomotives",
"create",
(payload) => locomotivesService.create(payload).then((r) => r.data),
undefined,
() => [["locomotives"]],
),
update: endpoint<
{ id: string; data: Partial<SaveLocomotivePayload> },
Locomotive
>(
"locomotives",
"update",
({ id, data }) => locomotivesService.update(id, data).then((r) => r.data),
undefined,
() => [["locomotives"]],
),
decommission: endpoint<string, void>(
"locomotives",
"decommission",
(id) => locomotivesService.decommission(id).then(() => undefined),
undefined,
() => [["locomotives"]],
),
},
cargoTypes: {
list: endpoint<void, unknown[]>("cargo-types", "list", () =>
cargoTypesService.getCargoTypes(),
),
},
payments: {
list: endpoint<{ filter?: PaymentListFilter }, PaginatedPayments>(
"payments",
"list",
({ filter }) => paymentsService.list(filter),
({ filter }) => ["payments", "list", filter ?? {}],
),
summary: endpoint<void, PaymentSummary>(
"payments",
"summary",
() => paymentsService.getSummary(),
() => ["payments", "summary"],
),
},
signatures: {
mySignature: endpoint<void, SavedSignature | null>(
"me",
"signature",
() => signaturesService.getMySignature(),
() => ["me", "signature"],
),
save: endpoint<SaveSignaturePayload, SavedSignature | null>(
"me",
"save-signature",
(payload) => signaturesService.saveMySignature(payload),
undefined,
() => [["me", "signature"]],
),
},
fleet: {
list: endpoint<
{ slug: FleetResourceSlug; filters?: FleetListFilters },
FleetRecord[]
>(
"fleet",
"list",
({ slug, filters }) => fleetService.list(slug, filters),
({ slug, filters }) => [...QUERY_KEYS.FLEET.list(slug), filters ?? {}],
),
create: endpoint<
{ slug: FleetResourceSlug; data: Record<string, unknown> },
unknown
>(
"fleet",
"create",
({ slug, data }) => fleetService.create(slug, data),
undefined,
({ slug }) => [QUERY_KEYS.FLEET.list(slug)],
),
update: endpoint<
{ slug: FleetResourceSlug; id: string; data: Record<string, unknown> },
unknown
>(
"fleet",
"update",
({ slug, id, data }) => fleetService.update(slug, id, data),
undefined,
({ slug }) => [QUERY_KEYS.FLEET.list(slug)],
),
remove: endpoint<{ slug: FleetResourceSlug; id: string }, unknown>(
"fleet",
"remove",
({ slug, id }) => fleetService.remove(slug, id),
undefined,
({ slug }) => [QUERY_KEYS.FLEET.list(slug)],
),
},
wagonTypes: {
list: endpoint<void, WagonType[]>("wagon-types", "list", () =>
wagonTypesService.getWagonTypes(),
),
create: endpoint<Partial<WagonType>, WagonType>(
"wagon-types",
"create",
(payload) => wagonTypesService.create(payload).then((r) => r.data),
undefined,
() => [["wagon-types"]],
),
update: endpoint<{ id: string; data: Partial<WagonType> }, WagonType>(
"wagon-types",
"update",
({ id, data }) => wagonTypesService.update(id, data).then((r) => r.data),
undefined,
() => [["wagon-types"]],
),
remove: endpoint<string, void>(
"wagon-types",
"remove",
(id) => wagonTypesService.delete(id).then(() => undefined),
undefined,
() => [["wagon-types"]],
),
},
cargoes: {
list: endpoint<void, Cargo[]>("cargoes", "list", () =>
cargoService.getAll().then((r) => r.data),
@@ -778,46 +1547,68 @@ export const api = {
"file-upload-settings",
"create",
(payload) => fileUploadSettingsService.create(payload),
undefined,
() => [["file-upload-settings"]],
),
update: endpoint<
{ id: string; dto: UpdateFileUploadSettingDto },
FileUploadSetting
>("file-upload-settings", "update", ({ id, dto }) =>
fileUploadSettingsService.update(id, dto),
>(
"file-upload-settings",
"update",
({ id, dto }) => fileUploadSettingsService.update(id, dto),
undefined,
() => [["file-upload-settings"]],
),
remove: endpoint<{ id: string }, void>(
"file-upload-settings",
"remove",
({ id }) => fileUploadSettingsService.remove(id),
undefined,
() => [["file-upload-settings"]],
),
replaceFields: endpoint<
{ id: string; fields: CreateFileUploadFieldDto[] },
FileUploadField[]
>("file-upload-settings", "replaceFields", ({ id, fields }) =>
fileUploadSettingsService.replaceFields(id, fields),
>(
"file-upload-settings",
"replaceFields",
({ id, fields }) => fileUploadSettingsService.replaceFields(id, fields),
undefined,
() => [["file-upload-settings"]],
),
addField: endpoint<
{ settingId: string; dto: CreateFileUploadFieldDto },
FileUploadField
>("file-upload-settings", "addField", ({ settingId, dto }) =>
fileUploadSettingsService.addField(settingId, dto),
>(
"file-upload-settings",
"addField",
({ settingId, dto }) => fileUploadSettingsService.addField(settingId, dto),
undefined,
() => [["file-upload-settings"]],
),
updateField: endpoint<
{ fieldId: string; dto: UpdateFileUploadFieldDto },
FileUploadField
>("file-upload-settings", "updateField", ({ fieldId, dto }) =>
fileUploadSettingsService.updateField(fieldId, dto),
>(
"file-upload-settings",
"updateField",
({ fieldId, dto }) => fileUploadSettingsService.updateField(fieldId, dto),
undefined,
() => [["file-upload-settings"]],
),
removeField: endpoint<{ fieldId: string }, void>(
"file-upload-settings",
"removeField",
({ fieldId }) => fileUploadSettingsService.removeField(fieldId),
undefined,
() => [["file-upload-settings"]],
),
},
@@ -844,46 +1635,68 @@ export const api = {
"dropdown-settings",
"create",
(payload) => dropdownSettingsService.create(payload),
undefined,
() => [["dropdown-settings"]],
),
update: endpoint<
{ id: string; dto: UpdateDropdownSettingDto },
DropdownSetting
>("dropdown-settings", "update", ({ id, dto }) =>
dropdownSettingsService.update(id, dto),
>(
"dropdown-settings",
"update",
({ id, dto }) => dropdownSettingsService.update(id, dto),
undefined,
() => [["dropdown-settings"]],
),
remove: endpoint<{ id: string }, void>(
"dropdown-settings",
"remove",
({ id }) => dropdownSettingsService.remove(id),
undefined,
() => [["dropdown-settings"]],
),
replaceOptions: endpoint<
{ id: string; options: CreateDropdownOptionDto[] },
DropdownOption[]
>("dropdown-settings", "replaceOptions", ({ id, options }) =>
dropdownSettingsService.replaceOptions(id, options),
>(
"dropdown-settings",
"replaceOptions",
({ id, options }) => dropdownSettingsService.replaceOptions(id, options),
undefined,
() => [["dropdown-settings"]],
),
addOption: endpoint<
{ id: string; dto: CreateDropdownOptionDto },
DropdownOption
>("dropdown-settings", "addOption", ({ id, dto }) =>
dropdownSettingsService.addOption(id, dto),
>(
"dropdown-settings",
"addOption",
({ id, dto }) => dropdownSettingsService.addOption(id, dto),
undefined,
() => [["dropdown-settings"]],
),
updateOption: endpoint<
{ optionId: string; dto: UpdateDropdownOptionDto },
DropdownOption
>("dropdown-settings", "updateOption", ({ optionId, dto }) =>
dropdownSettingsService.updateOption(optionId, dto),
>(
"dropdown-settings",
"updateOption",
({ optionId, dto }) => dropdownSettingsService.updateOption(optionId, dto),
undefined,
() => [["dropdown-settings"]],
),
removeOption: endpoint<{ optionId: string }, void>(
"dropdown-settings",
"removeOption",
({ optionId }) => dropdownSettingsService.removeOption(optionId),
undefined,
() => [["dropdown-settings"]],
),
},