Remove webisite.teamId related code. Clean up queries.

This commit is contained in:
Brian Cao 2023-04-13 20:57:22 -07:00
parent 081a126c01
commit 0335fd3529
4 changed files with 8 additions and 19 deletions

View File

@ -95,17 +95,11 @@ export async function canViewWebsite({ user, shareToken }: Auth, websiteId: stri
return false; return false;
} }
export async function canCreateWebsite({ user }: Auth, teamId?: string) { export async function canCreateWebsite({ user }: Auth) {
if (user.isAdmin) { if (user.isAdmin) {
return true; return true;
} }
if (teamId) {
const teamUser = await getTeamUser(teamId, user.id);
return hasPermission(teamUser?.role, PERMISSIONS.websiteCreate);
}
return hasPermission(user.role, PERMISSIONS.websiteCreate); return hasPermission(user.role, PERMISSIONS.websiteCreate);
} }

View File

@ -41,15 +41,17 @@ export default async (
const { name, domain, shareId } = req.body; const { name, domain, shareId } = req.body;
let website;
try { try {
await updateWebsite(websiteId, { name, domain, shareId }); website = await updateWebsite(websiteId, { name, domain, shareId });
} catch (e: any) { } catch (e: any) {
if (e.message.includes('Unique constraint') && e.message.includes('share_id')) { if (e.message.includes('Unique constraint') && e.message.includes('share_id')) {
return serverError(res, 'That share ID is already taken.'); return serverError(res, 'That share ID is already taken.');
} }
} }
return ok(res); return ok(res, website);
} }
if (req.method === 'DELETE') { if (req.method === 'DELETE') {

View File

@ -10,7 +10,6 @@ export interface WebsitesRequestBody {
name: string; name: string;
domain: string; domain: string;
shareId: string; shareId: string;
teamId?: string;
} }
export default async ( export default async (
@ -31,9 +30,9 @@ export default async (
} }
if (req.method === 'POST') { if (req.method === 'POST') {
const { name, domain, shareId, teamId } = req.body; const { name, domain, shareId } = req.body;
if (!(await canCreateWebsite(req.auth, teamId))) { if (!(await canCreateWebsite(req.auth))) {
return unauthorized(res); return unauthorized(res);
} }
@ -44,11 +43,7 @@ export default async (
shareId, shareId,
}; };
if (teamId) { data.userId = userId;
data.teamId = teamId;
} else {
data.userId = userId;
}
const website = await createWebsite(data); const website = await createWebsite(data);

View File

@ -13,7 +13,6 @@ export async function getEventMetrics(
endDate: Date; endDate: Date;
timezone: string; timezone: string;
unit: string; unit: string;
column: string;
filters: { filters: {
url: string; url: string;
eventName: string; eventName: string;
@ -40,7 +39,6 @@ async function relationalQuery(
endDate: Date; endDate: Date;
timezone: string; timezone: string;
unit: string; unit: string;
column: string;
filters: { filters: {
url: string; url: string;
eventName: string; eventName: string;