This commit is contained in:
Brian Cao 2022-10-11 19:37:38 -07:00
parent b0bed5e73a
commit c147742d7a
18 changed files with 84 additions and 52 deletions

View file

@ -1,14 +1,10 @@
import { methodNotAllowed, ok, unauthorized, getRandomChars } from 'next-basics';
import { deleteWebsite, getAccount, getWebsite, updateWebsite } from 'queries';
import { allowQuery } from 'lib/auth';
import { useAuth, useCors } from 'lib/middleware';
import { validate } from 'uuid';
import { getRandomChars, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { deleteWebsite, getAccount, getWebsite, getWebsiteByUuid, updateWebsite } from 'queries';
export default async (req, res) => {
const { id } = req.query;
const websiteId = +id;
const where = validate(id) ? { websiteUuid: id } : { id: +id };
const { id: websiteId } = req.query;
if (req.method === 'GET') {
await useCors(req, res);
@ -17,7 +13,7 @@ export default async (req, res) => {
return unauthorized(res);
}
const website = await getWebsite(where);
const website = await getWebsiteByUuid(websiteId);
return ok(res, website);
}
@ -33,7 +29,7 @@ export default async (req, res) => {
account = await getAccount({ accountUuid });
}
const website = await getWebsite(where);
const website = await getWebsite(websiteId);
const shareId = enable_share_url ? website.shareId || getRandomChars(8) : null;
@ -48,7 +44,7 @@ export default async (req, res) => {
shareId: shareId,
userId: account ? account.id : +owner,
},
where,
{ websiteUuid: websiteId },
);
return ok(res);