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;
}
export async function canCreateWebsite({ user }: Auth, teamId?: string) {
export async function canCreateWebsite({ user }: Auth) {
if (user.isAdmin) {
return true;
}
if (teamId) {
const teamUser = await getTeamUser(teamId, user.id);
return hasPermission(teamUser?.role, PERMISSIONS.websiteCreate);
}
return hasPermission(user.role, PERMISSIONS.websiteCreate);
}

View File

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

View File

@ -10,7 +10,6 @@ export interface WebsitesRequestBody {
name: string;
domain: string;
shareId: string;
teamId?: string;
}
export default async (
@ -31,9 +30,9 @@ export default async (
}
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);
}
@ -44,11 +43,7 @@ export default async (
shareId,
};
if (teamId) {
data.teamId = teamId;
} else {
data.userId = userId;
}
data.userId = userId;
const website = await createWebsite(data);

View File

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