This commit is contained in:
Brian Cao 2022-10-31 23:42:37 -07:00
parent 246e4e5f4f
commit 17041efaae
73 changed files with 491 additions and 874 deletions

View file

@ -5,7 +5,7 @@ export async function createWebsite(userId, data) {
return prisma.client.website
.create({
data: {
account: {
user: {
connect: {
id: userId,
},
@ -15,7 +15,7 @@ export async function createWebsite(userId, data) {
})
.then(async res => {
if (redis.enabled && res) {
await redis.set(`website:${res.websiteUuid}`, res.id);
await redis.set(`website:${res.id}`, 1);
}
return res;

View file

@ -1,28 +1,28 @@
import prisma from 'lib/prisma';
import redis, { DELETED } from 'lib/redis';
export async function deleteWebsite(websiteUuid) {
export async function deleteWebsite(id) {
const { client, transaction } = prisma;
return transaction([
client.pageview.deleteMany({
where: { session: { website: { websiteUuid } } },
where: { session: { website: { id } } },
}),
client.eventData.deleteMany({
where: { event: { session: { website: { websiteUuid } } } },
where: { event: { session: { website: { id } } } },
}),
client.event.deleteMany({
where: { session: { website: { websiteUuid } } },
where: { session: { website: { id } } },
}),
client.session.deleteMany({
where: { website: { websiteUuid } },
where: { website: { id } },
}),
client.website.delete({
where: { websiteUuid },
where: { id },
}),
]).then(async res => {
if (redis.enabled) {
await redis.set(`website:${websiteUuid}`, DELETED);
await redis.set(`website:${id}`, DELETED);
}
return res;

View file

@ -11,7 +11,7 @@ export async function getAllWebsites() {
},
],
include: {
account: {
user: {
select: {
username: true,
},
@ -19,5 +19,5 @@ export async function getAllWebsites() {
},
});
return data.map(i => ({ ...i, account: i.account.username }));
return data.map(i => ({ ...i, user: i.user.username }));
}

View file

@ -8,7 +8,7 @@ export async function getWebsite(where) {
})
.then(async data => {
if (redis.enabled && data) {
await redis.set(`website:${data.websiteUuid}`, data.id);
await redis.set(`website:${data.id}`, 1);
}
return data;

View file

@ -1,20 +1,20 @@
import prisma from 'lib/prisma';
export async function resetWebsite(websiteId) {
export async function resetWebsite(id) {
const { client, transaction } = prisma;
return transaction([
client.pageview.deleteMany({
where: { session: { website: { websiteUuid: websiteId } } },
where: { session: { website: { id } } },
}),
client.eventData.deleteMany({
where: { event: { session: { website: { websiteUuid: websiteId } } } },
where: { event: { session: { website: { id } } } },
}),
client.event.deleteMany({
where: { session: { website: { websiteUuid: websiteId } } },
where: { session: { website: { id } } },
}),
client.session.deleteMany({
where: { website: { websiteUuid: websiteId } },
where: { website: { id } },
}),
]);
}