mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Added error conditions for website updates.
This commit is contained in:
parent
4e756727ed
commit
e429abc08e
3 changed files with 599 additions and 621 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { getRandomChars, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getRandomChars, methodNotAllowed, ok, serverError, unauthorized } from 'next-basics';
|
||||
import { deleteWebsite, getAccount, getWebsite, updateWebsite } from 'queries';
|
||||
|
||||
export default async (req, res) => {
|
||||
|
|
@ -26,21 +26,31 @@ export default async (req, res) => {
|
|||
|
||||
if (accountUuid) {
|
||||
account = await getAccount({ accountUuid });
|
||||
|
||||
if (!account) {
|
||||
return serverError(res, 'Account does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
const website = await getWebsite({ websiteUuid: websiteId });
|
||||
|
||||
const newShareId = enableShareUrl ? website.shareId || getRandomChars(8) : null;
|
||||
|
||||
await updateWebsite(
|
||||
{
|
||||
name,
|
||||
domain,
|
||||
shareId: shareId ? shareId : newShareId,
|
||||
userId: account ? account.id : +owner,
|
||||
},
|
||||
{ websiteUuid: websiteId },
|
||||
);
|
||||
try {
|
||||
await updateWebsite(
|
||||
{
|
||||
name,
|
||||
domain,
|
||||
shareId: shareId ? shareId : newShareId,
|
||||
userId: account ? account.id : +owner || undefined,
|
||||
},
|
||||
{ websiteUuid: websiteId },
|
||||
);
|
||||
} catch (e) {
|
||||
if (e.message.includes('Unique constraint') && e.message.includes('share_id')) {
|
||||
return serverError(res, 'That share ID is already taken.');
|
||||
}
|
||||
}
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue