offers sliders
This commit is contained in:
1 parent
5e86a52d43
commit
54b1900c88
7 files changed
+46
-47
No files matched your search
+10
-9
@@ -63,19 +63,20 @@ 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.offerStatusSet(offer.id, Status.Accepted);
|
||||
return pg.offerStatusSet([offer.id], Status.Accepted);
|
||||
}
|
||||
|
||||
async function statusSet(user: User, id: UUID, status: Status) {
|
||||
log.info({ status, id }, 'setting offer status');
|
||||
async function statusSet(user: User, ids: UUID[], status: Status) {
|
||||
log.info({ status, ids }, 'setting offer status');
|
||||
|
||||
const offer = await pg.offerFindId(id);
|
||||
const update = await pg.offerStatusSet(offer.id, status);
|
||||
// const offer = await pg.offerFindId(ids);
|
||||
const update = await pg.offerStatusSet(ids, status);
|
||||
|
||||
if (status === Status.Complete) {
|
||||
log.info({ id, status }, 'completed offer, removing want...');
|
||||
await pg.wantRm(offer.wantId);
|
||||
}
|
||||
// forget about this for now
|
||||
// if (status === Status.Complete) {
|
||||
// log.info({ id, status }, 'completed offer, removing want...');
|
||||
// await pg.wantRm(offer.wantId);
|
||||
// }
|
||||
|
||||
return update;
|
||||
}
|
||||
|
||||
+3
-3
@@ -289,9 +289,9 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
);
|
||||
}
|
||||
|
||||
async function offerStatusSet(id: UUID, status: Status) {
|
||||
return prisma.offer.update({
|
||||
where: { id: id },
|
||||
async function offerStatusSet(ids: UUID[], status: Status) {
|
||||
return prisma.offer.updateMany({
|
||||
where: { id: { in: ids } },
|
||||
data: { status },
|
||||
});
|
||||
}
|
||||
|
||||
+4
-4
@@ -75,7 +75,7 @@ export type RpcMessage =
|
||||
|
||||
|
||||
type OfferStatusSetParams = {
|
||||
id: UUID,
|
||||
ids: UUID[],
|
||||
status: Status,
|
||||
};
|
||||
|
||||
@@ -109,11 +109,11 @@ export default function createRpc(log: Log, pg: Pg, ws, discogs: Discogs, offers
|
||||
}
|
||||
|
||||
async function offerStatusSet(params: OfferStatusSetParams): Promise<OffersMessage> {
|
||||
const { id, status } = params;
|
||||
assert(id, 'no id supplied');
|
||||
const { ids, status } = params;
|
||||
assert(ids, 'no ids supplied');
|
||||
assert(Status[status], 'unknown status');
|
||||
|
||||
const offer = await offers.statusSet(user, id, status);
|
||||
const offer = await offers.statusSet(user, ids, status);
|
||||
const userOffers = await offers.userOffers(user);
|
||||
|
||||
events.emit(Events.DiscordMessage, { msg: 'user offer event', user: user.email, offer })
|
||||
|
||||
Reference in new issue
Block a user