Skip to content

Commit 2412ddb

Browse files
henrikhenrikperssonHenrik Persson
andauthored
MIM-462: Add endpoints for getting work orders from xpand (#293)
* Update generated types * Add endpoints for getting work orders from xpand --------- Co-authored-by: Henrik Persson <henrik.persson@iteam.com>
1 parent 9a0aa9c commit 2412ddb

File tree

9 files changed

+801
-46
lines changed

9 files changed

+801
-46
lines changed

src/adapters/tests/work-order-adapter.test.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,113 @@ describe('work-order-adapter', () => {
5959
})
6060
})
6161

62+
describe(workOrderAdapter.getXpandWorkOrdersByRentalPropertyId, () => {
63+
const rentalPropertyId = '406-028-02-0101'
64+
const xpandWorkOrderMock = factory.xpandWorkOrder.buildList(3)
65+
66+
it('returns err if request fails', async () => {
67+
mockServer.use(
68+
http.get(
69+
`${config.workOrderService.url}/workOrders/xpand/residenceId/${rentalPropertyId}`,
70+
() => new HttpResponse(null, { status: 500 })
71+
)
72+
)
73+
74+
const result =
75+
await workOrderAdapter.getXpandWorkOrdersByRentalPropertyId(
76+
rentalPropertyId
77+
)
78+
79+
expect(result.ok).toBe(false)
80+
if (!result.ok) expect(result.err).toBe('unknown')
81+
})
82+
83+
it('returns work order data', async () => {
84+
mockServer.use(
85+
http.get(
86+
`${config.workOrderService.url}/workOrders/xpand/residenceId/${rentalPropertyId}`,
87+
() =>
88+
HttpResponse.json(
89+
{
90+
content: { workOrders: xpandWorkOrderMock },
91+
},
92+
{ status: 200 }
93+
)
94+
)
95+
)
96+
97+
const result =
98+
await workOrderAdapter.getXpandWorkOrdersByRentalPropertyId(
99+
rentalPropertyId
100+
)
101+
102+
expect(result).toMatchObject({
103+
ok: true,
104+
data: xpandWorkOrderMock,
105+
})
106+
})
107+
})
108+
109+
describe(workOrderAdapter.getXpandWorkOrderDetails, () => {
110+
const workOrderCode = '25-000050'
111+
const xpandWorkOrderDetailsMock = factory.xpandWorkOrderDetails.build({
112+
Code: workOrderCode,
113+
})
114+
115+
it('returns err if request fails', async () => {
116+
mockServer.use(
117+
http.get(
118+
`${config.workOrderService.url}/workOrders/xpand/${workOrderCode}`,
119+
() => new HttpResponse(null, { status: 500 })
120+
)
121+
)
122+
123+
const result =
124+
await workOrderAdapter.getXpandWorkOrderDetails(workOrderCode)
125+
126+
expect(result.ok).toBe(false)
127+
if (!result.ok) expect(result.err).toBe('unknown')
128+
})
129+
130+
it('returns not-found if work order is not found', async () => {
131+
mockServer.use(
132+
http.get(
133+
`${config.workOrderService.url}/workOrders/xpand/${workOrderCode}`,
134+
() => new HttpResponse(null, { status: 404 })
135+
)
136+
)
137+
138+
const result =
139+
await workOrderAdapter.getXpandWorkOrderDetails(workOrderCode)
140+
141+
expect(result.ok).toBe(false)
142+
if (!result.ok) expect(result.err).toBe('not-found')
143+
})
144+
145+
it('returns work order data', async () => {
146+
mockServer.use(
147+
http.get(
148+
`${config.workOrderService.url}/workOrders/xpand/${workOrderCode}`,
149+
() =>
150+
HttpResponse.json(
151+
{
152+
content: xpandWorkOrderDetailsMock,
153+
},
154+
{ status: 200 }
155+
)
156+
)
157+
)
158+
159+
const result =
160+
await workOrderAdapter.getXpandWorkOrderDetails(workOrderCode)
161+
162+
expect(result).toMatchObject({
163+
ok: true,
164+
data: xpandWorkOrderDetailsMock,
165+
})
166+
})
167+
})
168+
62169
describe(workOrderAdapter.createWorkOrder, () => {
63170
const createWorkOrderMock = factory.createWorkOrder.build()
64171
it('returns err if request fails', async () => {

src/adapters/work-order-adapter/generated/api-types.ts

Lines changed: 212 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,147 @@ export interface paths {
221221
patch?: never;
222222
trace?: never;
223223
};
224+
"/workOrders/xpand/residenceId/{residenceId}": {
225+
parameters: {
226+
query?: never;
227+
header?: never;
228+
path?: never;
229+
cookie?: never;
230+
};
231+
/**
232+
* Get work orders by residence id from xpand
233+
* @description Retrieves work orders from xpand based on the provided residence id.
234+
*/
235+
get: {
236+
parameters: {
237+
query?: {
238+
/** @description The number of work orders to skip. */
239+
skip?: number;
240+
/** @description The number of work orders to fetch. */
241+
limit?: number;
242+
/** @description Whether to sort the work orders by ascending creation date. */
243+
sortAscending?: boolean;
244+
};
245+
header?: never;
246+
path: {
247+
/** @description The residence id to filter work orders. */
248+
residenceId: string;
249+
};
250+
cookie?: never;
251+
};
252+
requestBody?: never;
253+
responses: {
254+
/** @description Successfully retrieved work orders. */
255+
200: {
256+
headers: {
257+
[name: string]: unknown;
258+
};
259+
content: {
260+
"application/json": {
261+
content?: {
262+
workOrders?: components["schemas"]["XpandWorkOrder"][];
263+
};
264+
/** @description Route metadata */
265+
metadata?: Record<string, never>;
266+
};
267+
};
268+
};
269+
/** @description Internal server error. Failed to retrieve work orders. */
270+
500: {
271+
headers: {
272+
[name: string]: unknown;
273+
};
274+
content: {
275+
"application/json": {
276+
/** @example Internal server error */
277+
error?: string;
278+
/** @description Route metadata */
279+
metadata?: Record<string, never>;
280+
};
281+
};
282+
};
283+
};
284+
};
285+
put?: never;
286+
post?: never;
287+
delete?: never;
288+
options?: never;
289+
head?: never;
290+
patch?: never;
291+
trace?: never;
292+
};
293+
"/workOrders/xpand/{code}": {
294+
parameters: {
295+
query?: never;
296+
header?: never;
297+
path?: never;
298+
cookie?: never;
299+
};
300+
/**
301+
* Get work order details by work order code from xpand
302+
* @description Retrieves work order details from xpand.
303+
*/
304+
get: {
305+
parameters: {
306+
query?: never;
307+
header?: never;
308+
path: {
309+
/** @description The work order code to fetch details for. */
310+
code: string;
311+
};
312+
cookie?: never;
313+
};
314+
requestBody?: never;
315+
responses: {
316+
/** @description Successfully retrieved work order. */
317+
200: {
318+
headers: {
319+
[name: string]: unknown;
320+
};
321+
content: {
322+
"application/json": {
323+
content?: components["schemas"]["XpandWorkOrderDetails"];
324+
/** @description Route metadata */
325+
metadata?: Record<string, never>;
326+
};
327+
};
328+
};
329+
/** @description Work order not found. */
330+
404: {
331+
headers: {
332+
[name: string]: unknown;
333+
};
334+
content: {
335+
"application/json": {
336+
/** @example Work order not found */
337+
error?: string;
338+
};
339+
};
340+
};
341+
/** @description Internal server error. Failed to retrieve work order. */
342+
500: {
343+
headers: {
344+
[name: string]: unknown;
345+
};
346+
content: {
347+
"application/json": {
348+
/** @example Internal server error */
349+
error?: string;
350+
/** @description Route metadata */
351+
metadata?: Record<string, never>;
352+
};
353+
};
354+
};
355+
};
356+
};
357+
put?: never;
358+
post?: never;
359+
delete?: never;
360+
options?: never;
361+
head?: never;
362+
patch?: never;
363+
trace?: never;
364+
};
224365
"/workOrders": {
225366
parameters: {
226367
query?: never;
@@ -486,6 +627,40 @@ export interface components {
486627
}[];
487628
Url?: string;
488629
};
630+
XpandWorkOrder: {
631+
AccessCaption: string;
632+
Caption: string | null;
633+
Code: string;
634+
ContactCode: string | null;
635+
Id: string;
636+
/** Format: date-time */
637+
LastChanged: string;
638+
Priority: string | null;
639+
/** Format: date-time */
640+
Registered: string;
641+
RentalObjectCode: string;
642+
Status: string;
643+
};
644+
XpandWorkOrderDetails: {
645+
AccessCaption: string;
646+
Caption: string | null;
647+
Code: string;
648+
ContactCode: string | null;
649+
Description: string;
650+
Id: string;
651+
/** Format: date-time */
652+
LastChanged: string;
653+
Priority: string | null;
654+
/** Format: date-time */
655+
Registered: string;
656+
RentalObjectCode: string;
657+
Status: string;
658+
WorkOrderRows: {
659+
Description: string | null;
660+
LocationCode: string | null;
661+
EquipmentCode: string | null;
662+
}[];
663+
};
489664
CreateWorkOrderBody: {
490665
rentalProperty: {
491666
id: string;
@@ -560,6 +735,30 @@ export interface components {
560735
}[];
561736
};
562737
};
738+
CreateWorkOrderDetails: {
739+
ContactCode: string;
740+
RentalObjectCode: string;
741+
AccessOptions: {
742+
Type: number;
743+
PhoneNumber: string | null;
744+
Email: string;
745+
CallBetween: string;
746+
};
747+
HearingImpaired: boolean;
748+
Pet: string;
749+
Rows: {
750+
LocationCode: string;
751+
PartOfBuildingCode: string;
752+
Description: string;
753+
MaintenanceUnitCode?: (unknown | string) | null;
754+
MaintenanceUnitCaption?: (unknown | string) | null;
755+
}[];
756+
Images: {
757+
Filename: string;
758+
ImageType: number;
759+
Base64String: string;
760+
}[];
761+
};
563762
Lease: {
564763
leaseId: string;
565764
leaseNumber: string;
@@ -569,6 +768,19 @@ export interface components {
569768
contractDate?: string;
570769
approvalDate?: string;
571770
};
771+
Tenant: {
772+
contactCode: string;
773+
contactKey: string;
774+
firstName?: string;
775+
lastName?: string;
776+
nationalRegistrationNumber?: string;
777+
phoneNumbers?: {
778+
phoneNumber: string;
779+
type: string;
780+
isMainNumber: number;
781+
}[];
782+
emailAddress?: string;
783+
};
572784
RentalProperty: {
573785
id: string;
574786
type: string;
@@ -595,43 +807,6 @@ export interface components {
595807
estate: string;
596808
}[];
597809
};
598-
Tenant: {
599-
contactCode: string;
600-
contactKey: string;
601-
firstName?: string;
602-
lastName?: string;
603-
nationalRegistrationNumber?: string;
604-
phoneNumbers?: {
605-
phoneNumber: string;
606-
type: string;
607-
isMainNumber: number;
608-
}[];
609-
emailAddress?: string;
610-
};
611-
CreateWorkOrderDetails: {
612-
ContactCode: string;
613-
RentalObjectCode: string;
614-
AccessOptions: {
615-
Type: number;
616-
PhoneNumber: string | null;
617-
Email: string;
618-
CallBetween: string;
619-
};
620-
HearingImpaired: boolean;
621-
Pet: string;
622-
Rows: {
623-
LocationCode: string;
624-
PartOfBuildingCode: string;
625-
Description: string;
626-
MaintenanceUnitCode?: (unknown | string) | null;
627-
MaintenanceUnitCaption?: (unknown | string) | null;
628-
}[];
629-
Images: {
630-
Filename: string;
631-
ImageType: number;
632-
Base64String: string;
633-
}[];
634-
};
635810
};
636811
responses: never;
637812
parameters: never;

0 commit comments

Comments
 (0)