prod nginx changes and remove want on offer complete

This commit is contained in:
ntr committed 2022-09-15 22:14:54 +10:00
1 parent 2c66c47163
commit 644398319d
6 files changed
+52 -18

No files matched your search

+1
View File
@@ -2,5 +2,6 @@
push offers
cover off admin routes and commands
remove want on offer complete
do we keep historical offers / wants?
+12 -4
View File
@@ -5,7 +5,7 @@ import groupBy from 'lodash/groupBy';
import sortBy from 'lodash/sortBy';
import { Context } from 'koa';
import { logAxiosError } from './utils';
import { logAxiosError, wantDetails } from './utils';
import { Pg } from './pg';
export enum Status {
@@ -65,9 +65,17 @@ export default function createOffers(log: Log, pg: Pg) {
}
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);
log.info({ status, id }, 'setting offer status');
const offer = await pg.offerFindId(id);
const update = await pg.offerStatusSet(offer.id, status);
if (status === Status.Complete) {
log.info({ id, status }, 'completed offer, removing want...');
await pg.wantRm(offer.wantId);
}
return update;
}
async function bundles() {
+23
View File
@@ -27,12 +27,14 @@ export interface Pg {
wantCreate: (discogsWant: any, user: User) => Promise<Want>,
wantList: (user: User) => Promise<Want[]>,
wantsToSync: () => Promise<Want[]>,
wantRm: (id: UUID) => Promise<void>,
bundleCandidates: () => Promise<Listing[][]>,
offersCreate: (offers: Offer[]) => Promise<Offer[]>,
offerStatusSet: (id: UUID, status: Status) => Promise<Offer>,
offersAdmin: () => Promise<Offer[]>,
offerFindId: (id: UUID) => Promise<Offer>,
}
export default function createPg(log: Log, prisma: PrismaClient): Pg {
@@ -60,6 +62,15 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
});
}
async function offerFindId(id: UUID) {
return prisma.offer.findFirstOrThrow({
where: { id },
include: {
want: true,
}
});
}
async function userOfferFind(user: User, id: UUID) {
return prisma.offer.findFirstOrThrow({
where: {
@@ -86,6 +97,9 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
});
}
// userUpdate({ email: 'jen@vdk.com', password: 'jen' });
// userUpdate({ email: 'james@mcd', password: 'james' });
async function userUpdate(params: UserCreateParams) {
const hashRounds = 10;
const password = await bcrypt.hash(params.password, hashRounds);
@@ -111,6 +125,12 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
return prisma.want.findMany({});
}
async function wantRm(id: UUID) {
await prisma.want.delete({
where: { id },
});
}
async function wantCreate(discogsRelease, user) {
const data: { userId: UUID, release: DiscogsListing, data: any } = {
data: discogsRelease,
@@ -286,6 +306,8 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
wantCreate,
wantList,
wantsToSync,
wantRm,
listingUpsert,
listingFind,
listingRmUnlisted,
@@ -296,5 +318,6 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
offersCreate,
offerStatusSet,
offersAdmin,
offerFindId,
};
}
+3 -1
View File
@@ -23,4 +23,6 @@ export function wantDetails(want: Want) {
artist: data.artists_sort,
id: want.id
}
}
}
export function offerDetails() {}
+5 -1
View File
@@ -5,6 +5,10 @@ import { useSelector, useDispatch } from 'react-redux'
import http from './../http';
import { State, userState } from './../store';
function showAdmin(user) {
return user && user.email === 'ntr@mnml.gg';
}
const Header = () => {
const dispatch = useDispatch()
const user = useSelector((state: State) => state.user);
@@ -48,7 +52,7 @@ const Header = () => {
return (
<header>
{user ? nav() : anonNav()}
{user ? adminNav() : null}
{showAdmin(user) ? adminNav() : <div></div>}
{user ? userNav() : null}
</header>
);
+8 -12
View File
@@ -6,16 +6,11 @@ upstream mcrates_client {
server client:8080;
}
# upstream mcrates_ws {
# server 127.0.0.1:40055;
# }
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# DEV
server {
server_name matescrates.au;
@@ -30,13 +25,14 @@ server {
proxy_read_timeout 600s;
}
# location /api/ws {
# proxy_pass http://mcrates_ws;
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection $connection_upgrade;
# proxy_read_timeout 600s;
# }
location /api/ws {
proxy_pass http://mcrates_api;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_read_timeout 600s;
}
location /api/ {
# trailing slash means api will receive url WITHOUT /api