Skip to content

Commit 3c1ffc4

Browse files
author
Zuhwa
committed
add mapping and job helper
1 parent 5b455ba commit 3c1ffc4

3 files changed

Lines changed: 99 additions & 7 deletions

File tree

src/acpClient.ts

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,24 @@ class AcpClient {
293293
if (data.error) {
294294
throw new Error(data.error.message);
295295
}
296-
return data;
296+
297+
return data.data.map((job) => {
298+
return new AcpJob(
299+
this,
300+
job.onChainJobId,
301+
job.sellerAddress,
302+
job.memos.map((memo) => {
303+
return new AcpMemo(
304+
this,
305+
memo.memoId,
306+
memo.memoType,
307+
memo.content,
308+
memo.nextPhase
309+
);
310+
}),
311+
job.phase
312+
);
313+
});
297314
} catch (error) {
298315
throw error;
299316
}
@@ -314,7 +331,24 @@ class AcpClient {
314331
if (data.error) {
315332
throw new Error(data.error.message);
316333
}
317-
return data;
334+
335+
return data.data.map((job) => {
336+
return new AcpJob(
337+
this,
338+
job.onChainJobId,
339+
job.sellerAddress,
340+
job.memos.map((memo) => {
341+
return new AcpMemo(
342+
this,
343+
memo.memoId,
344+
memo.memoType,
345+
memo.content,
346+
memo.nextPhase
347+
);
348+
}),
349+
job.phase
350+
);
351+
});
318352
} catch (error) {
319353
throw error;
320354
}
@@ -335,7 +369,23 @@ class AcpClient {
335369
if (data.error) {
336370
throw new Error(data.error.message);
337371
}
338-
return data;
372+
return data.data.map((job) => {
373+
return new AcpJob(
374+
this,
375+
job.onChainJobId,
376+
job.sellerAddress,
377+
job.memos.map((memo) => {
378+
return new AcpMemo(
379+
this,
380+
memo.memoId,
381+
memo.memoType,
382+
memo.content,
383+
memo.nextPhase
384+
);
385+
}),
386+
job.phase
387+
);
388+
});
339389
} catch (error) {
340390
throw error;
341391
}
@@ -356,7 +406,27 @@ class AcpClient {
356406
if (data.error) {
357407
throw new Error(data.error.message);
358408
}
359-
return data;
409+
410+
const job = data.data;
411+
if (!job) {
412+
return;
413+
}
414+
415+
return new AcpJob(
416+
this,
417+
job.onChainJobId,
418+
job.sellerAddress,
419+
job.memos.map((memo) => {
420+
return new AcpMemo(
421+
this,
422+
memo.memoId,
423+
memo.memoType,
424+
memo.content,
425+
memo.nextPhase
426+
);
427+
}),
428+
job.phase
429+
);
360430
} catch (error) {
361431
throw error;
362432
}
@@ -377,7 +447,19 @@ class AcpClient {
377447
if (data.error) {
378448
throw new Error(data.error.message);
379449
}
380-
return data;
450+
451+
const memo = data.data;
452+
if (!memo) {
453+
return;
454+
}
455+
456+
return new AcpMemo(
457+
this,
458+
memo.memoId,
459+
memo.memoType,
460+
memo.content,
461+
memo.nextPhase
462+
);
381463
} catch (error) {
382464
throw error;
383465
}

src/acpJob.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ class AcpJob {
1111
public phase: AcpJobPhases
1212
) {}
1313

14+
public get serviceRequirement() {
15+
return this.memos.find((m) => m.nextPhase === AcpJobPhases.NEGOTIATION)
16+
?.content;
17+
}
18+
19+
public get deliverable() {
20+
return this.memos.find((m) => m.nextPhase === AcpJobPhases.COMPLETED)
21+
?.content;
22+
}
23+
1424
async pay(amount: number, reason?: string) {
1525
const memo = this.memos.find(
1626
(m) => m.nextPhase === AcpJobPhases.TRANSACTION

src/acpMemo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import AcpClient from "./acpClient";
2-
import { MemoType } from "./acpContractClient";
2+
import { AcpJobPhases, MemoType } from "./acpContractClient";
33

44
class AcpMemo {
55
constructor(
66
private acpClient: AcpClient,
77
public id: number,
88
public type: MemoType,
99
public content: string,
10-
public nextPhase: number
10+
public nextPhase: AcpJobPhases
1111
) {}
1212

1313
async create(jobId: number, isSecured: boolean = true) {

0 commit comments

Comments
 (0)