This commit is contained in:
ntr committed 2022-09-11 21:16:33 +10:00
1 parent 111f690482
commit 2c66c47163
14 files changed
+168 -58

No files matched your search

+14 -6
View File
@@ -1,5 +1,6 @@
import type Log from 'bunyan';
import type { PrismaClient, Want, User, Listing, Offer, } from '@prisma/client';
import assert from 'assert/strict';
import groupBy from 'lodash/groupBy';
import sortBy from 'lodash/sortBy';
import { Context } from 'koa';
@@ -8,11 +9,11 @@ import { logAxiosError } from './utils';
import { Pg } from './pg';
export enum Status {
Pending = 'pending',
Accepted = 'accepted',
Declined = 'declined',
Ordered = 'ordered',
Complete = 'complete',
Pending = 'Pending',
Accepted = 'Accepted',
Declined = 'Declined',
Ordered = 'Ordered',
Complete = 'Complete',
}
export default function createOffers(log: Log, pg: Pg) {
@@ -60,7 +61,13 @@ export default function createOffers(log: Log, pg: Pg) {
// check the user actually has this offer
const offer = await pg.userOfferFind(ctx.state.user, id);
return pg.offerSetStatus(offer.id, Status.Accepted);
return pg.offerStatusSet(offer.id, Status.Accepted);
}
async function statusSet(user: User, id: UUID, status: Status) {
// check the user actually has this offer
const offer = await pg.userOfferFind(user, id);
return pg.offerStatusSet(offer.id, status);
}
async function bundles() {
@@ -108,5 +115,6 @@ export default function createOffers(log: Log, pg: Pg) {
generate,
accept,
bundles,
statusSet,
};
}