Added getWebsite method.

This commit is contained in:
Mike Cao 2022-10-06 14:18:27 -07:00
parent 0387cf0da0
commit d8c440453c
4 changed files with 16 additions and 6 deletions

View file

@ -1,12 +1,14 @@
import { getRandomChars, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { deleteWebsite, getWebsiteById, updateWebsite } from 'queries';
import { deleteWebsite, getWebsite, getWebsiteById, updateWebsite } from 'queries';
import { allowQuery } from 'lib/auth';
import { useAuth, useCors } from 'lib/middleware';
import { validate } from 'uuid';
export default async (req, res) => {
const { id } = req.query;
const websiteId = +id;
const where = validate(id) ? { website_uuid: id } : { website_id: +id };
if (req.method === 'GET') {
await useCors(req, res);
@ -15,7 +17,7 @@ export default async (req, res) => {
return unauthorized(res);
}
const website = await getWebsiteById(websiteId);
const website = await getWebsite(where);
return ok(res, website);
}