wants wip"
This commit is contained in:
1 parent
c99f6fd2b6
commit
f5e75f4fe6
7 files changed
+33
-12
No files matched your search
+10
-2
@@ -147,7 +147,7 @@ export default function createApi(log: Log, pg: Pg, discogs) {
|
|||||||
ctx.response.body = listings;
|
ctx.response.body = listings;
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/want', async function wantPost(ctx, next) {
|
router.get('/wants', async function wantPost(ctx, next) {
|
||||||
const { userId, releaseId } = ctx.request.body;
|
const { userId, releaseId } = ctx.request.body;
|
||||||
const user = await pg.userFindId(userId);
|
const user = await pg.userFindId(userId);
|
||||||
const release = await discogs.release(releaseId);
|
const release = await discogs.release(releaseId);
|
||||||
@@ -155,7 +155,15 @@ export default function createApi(log: Log, pg: Pg, discogs) {
|
|||||||
ctx.response.body = want;
|
ctx.response.body = want;
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/want/search', async function wantPost(ctx, next) {
|
router.get('/wants', async function wantGet(ctx, next) {
|
||||||
|
ctx.assert(ctx.isAuthenticated(), 401, 'log in required');
|
||||||
|
log.warn(ctx.state.user);
|
||||||
|
const user = ctx.state.user;
|
||||||
|
const wants = await pg.wantFind(user);
|
||||||
|
ctx.response.body = wants;
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/wants/search', async function wantPost(ctx, next) {
|
||||||
const { artist, title } = ctx.request.body;
|
const { artist, title } = ctx.request.body;
|
||||||
const results = await discogs.search(artist, title);
|
const results = await discogs.search(artist, title);
|
||||||
ctx.response.body = results;
|
ctx.response.body = results;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export interface Pg {
|
|||||||
userWants: (user: User) => Promise<Want[]>,
|
userWants: (user: User) => Promise<Want[]>,
|
||||||
|
|
||||||
wantUpsert: (want: Want, user: User) => Promise<Want>,
|
wantUpsert: (want: Want, user: User) => Promise<Want>,
|
||||||
|
wantFind: (user: User) => Promise<Want[]>,
|
||||||
listingUpsert: (listing: Listing, want: Want) => Promise<Listing>,
|
listingUpsert: (listing: Listing, want: Want) => Promise<Listing>,
|
||||||
listingFind: (id: DiscogsListing) => Promise<Listing>,
|
listingFind: (id: DiscogsListing) => Promise<Listing>,
|
||||||
listingRmUnlisted: (want: Want, ids: DiscogsListing[]) => Promise<number>,
|
listingRmUnlisted: (want: Want, ids: DiscogsListing[]) => Promise<number>,
|
||||||
@@ -53,6 +54,12 @@ export default function createPg(log: Log, prisma: PrismaClient): Pg {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function wantList(user: User) {
|
||||||
|
return prisma.want.findMany({
|
||||||
|
where: { userId: user.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function wantUpsert(dcWant, user) {
|
async function wantUpsert(dcWant, user) {
|
||||||
const values: { userId: UUID, release: DiscogsListing, data: any } = {
|
const values: { userId: UUID, release: DiscogsListing, data: any } = {
|
||||||
data: dcWant,
|
data: dcWant,
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ const actions = {
|
|||||||
return api.get(`/user/${userId}/offers`);
|
return api.get(`/user/${userId}/offers`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getWants: async function getWants() {
|
||||||
|
return api.get('/wants');
|
||||||
|
},
|
||||||
|
|
||||||
getLogin: async function getLogin() {
|
getLogin: async function getLogin() {
|
||||||
return api.get('/auth/login')
|
return api.get('/auth/login')
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-4
@@ -2,7 +2,6 @@ import { h } from 'preact';
|
|||||||
import { useState, useEffect } from 'preact/hooks';
|
import { useState, useEffect } from 'preact/hooks';
|
||||||
import { Route, Router, route } from 'preact-router';
|
import { Route, Router, route } from 'preact-router';
|
||||||
|
|
||||||
// import mcratesStore from './store';
|
|
||||||
import actions from './actions';
|
import actions from './actions';
|
||||||
|
|
||||||
import Header from './components/header';
|
import Header from './components/header';
|
||||||
@@ -12,8 +11,6 @@ import Login from './routes/login';
|
|||||||
import Search from './routes/search';
|
import Search from './routes/search';
|
||||||
import User from './routes/user';
|
import User from './routes/user';
|
||||||
|
|
||||||
// const store = mcratesStore();
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [user, setUser] = useState(null);
|
const [user, setUser] = useState(null);
|
||||||
|
|
||||||
@@ -41,7 +38,7 @@ function App() {
|
|||||||
<Route path="/" component={Home} />
|
<Route path="/" component={Home} />
|
||||||
<Route path="/login" component={Login} success={loginSuccess} />
|
<Route path="/login" component={Login} success={loginSuccess} />
|
||||||
<Route path="/search" component={Search} />
|
<Route path="/search" component={Search} />
|
||||||
<Route path="/user/:userId" component={User} />
|
<Route path="/list/" component={User} user={user} />
|
||||||
</Router>
|
</Router>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ const Header = ({ user }) => {
|
|||||||
const nav = () => (
|
const nav = () => (
|
||||||
<nav>
|
<nav>
|
||||||
<a href="/search">Offers</a>
|
<a href="/search">Offers</a>
|
||||||
|
<a href='/list'>List</a>
|
||||||
<a href="/search">Search</a>
|
<a href="/search">Search</a>
|
||||||
<a href={`/user/${user.id}`}>List</a>
|
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const User = () => {
|
|||||||
const [noResults, setNoResults] = useState(false);
|
const [noResults, setNoResults] = useState(false);
|
||||||
|
|
||||||
async function fetchResults() {
|
async function fetchResults() {
|
||||||
const { data } = await axios.post(`http://localhost:41337/want/search`, {
|
const { data } = await axios.post(`http://localhost:41337/wants/search`, {
|
||||||
artist,
|
artist,
|
||||||
title,
|
title,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,17 +6,22 @@ import actions from './../actions';
|
|||||||
import Bundle from './../components/bundle';
|
import Bundle from './../components/bundle';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
userId: string,
|
user: any,
|
||||||
offers: any[],
|
offers: any[],
|
||||||
getUserOffers: (userId: string) => void,
|
getUserOffers: (userId: string) => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
const User = ({ userId }: Props) => {
|
const User = ({ user }: Props) => {
|
||||||
const [offers, setOffers] = useState([]);
|
const [offers, setOffers] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
actions.getOffers(userId).then(setOffers);
|
async function getWants() {
|
||||||
}, [userId]);
|
const [error, wants] = await actions.getWants();
|
||||||
|
if (error) return console.error(error);
|
||||||
|
setOffers(wants);
|
||||||
|
}
|
||||||
|
getWants();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
if (!offers.length) {
|
if (!offers.length) {
|
||||||
|
|||||||
Reference in new issue
Block a user