Moved code into src folder. Added build for component library.

This commit is contained in:
Mike Cao 2023-08-21 02:06:09 -07:00
parent 7a7233ead4
commit ede658771e
490 changed files with 749 additions and 442 deletions

View file

@ -0,0 +1,47 @@
import { secret } from 'lib/crypto';
import { useValidate } from 'lib/middleware';
import { NextApiRequestQueryBody } from 'lib/types';
import { NextApiResponse } from 'next';
import { createToken, methodNotAllowed, notFound, ok } from 'next-basics';
import { getWebsiteByShareId } from 'queries';
import * as yup from 'yup';
export interface ShareRequestQuery {
id: string;
}
export interface ShareResponse {
id: string;
token: string;
}
const schema = {
GET: yup.object().shape({
id: yup.string().uuid().required(),
}),
};
export default async (
req: NextApiRequestQueryBody<ShareRequestQuery>,
res: NextApiResponse<ShareResponse>,
) => {
req.yup = schema;
await useValidate(req, res);
const { id: shareId } = req.query;
if (req.method === 'GET') {
const website = await getWebsiteByShareId(shareId);
if (website) {
const data = { websiteId: website.id };
const token = createToken(data, secret());
return ok(res, { ...data, token });
}
return notFound(res);
}
return methodNotAllowed(res);
};