Feat/um 62 prisma property names (#1562)

* checkpoint

* fix pg schema

* fix mysql schema

* change property names
This commit is contained in:
Brian Cao 2022-10-10 13:42:18 -07:00 committed by GitHub
parent 36edbe2f4c
commit 78338205a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 431 additions and 433 deletions

View file

@ -1,4 +1,4 @@
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
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';
@ -8,7 +8,7 @@ export default async (req, res) => {
const { id } = req.query;
const websiteId = +id;
const where = validate(id) ? { website_uuid: id } : { website_id: +id };
const where = validate(id) ? { websiteUuid: id } : { id: +id };
if (req.method === 'GET') {
await useCors(req, res);
@ -25,17 +25,19 @@ export default async (req, res) => {
if (req.method === 'POST') {
await useAuth(req, res);
const { is_admin: currentUserIsAdmin, user_id: currentUserId, account_uuid } = req.auth;
const { name, domain, owner, share_id } = req.body;
const { isAdmin: currentUserIsAdmin, userId: currentUserId, accountUuid } = req.auth;
const { name, domain, owner, enable_share_url } = req.body;
let account;
if (account_uuid) {
account = await getAccount({ account_uuid });
if (accountUuid) {
account = await getAccount({ accountUuid });
}
const website = await getWebsite(where);
if (website.user_id !== currentUserId && !currentUserIsAdmin) {
const shareId = enable_share_url ? website.shareId || getRandomChars(8) : null;
if (website.userId !== currentUserId && !currentUserIsAdmin) {
return unauthorized(res);
}
@ -43,8 +45,8 @@ export default async (req, res) => {
{
name,
domain,
share_id: share_id || null,
user_id: account ? account.id : +owner,
shareId: shareId,
userId: account ? account.id : +owner,
},
where,
);