mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Feat/um 62 prisma property names (#1562)
* checkpoint * fix pg schema * fix mysql schema * change property names
This commit is contained in:
parent
36edbe2f4c
commit
78338205a3
65 changed files with 431 additions and 433 deletions
|
|
@ -1,40 +1,40 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import redis, { DELETED } from 'lib/redis';
|
||||
|
||||
export async function deleteAccount(user_id) {
|
||||
export async function deleteAccount(userId) {
|
||||
const { client } = prisma;
|
||||
|
||||
const websites = await client.website.findMany({
|
||||
where: { user_id },
|
||||
select: { website_uuid: true },
|
||||
where: { userId },
|
||||
select: { websiteUuid: true },
|
||||
});
|
||||
|
||||
let websiteUuids = [];
|
||||
|
||||
if (websites.length > 0) {
|
||||
websiteUuids = websites.map(a => a.website_uuid);
|
||||
websiteUuids = websites.map(a => a.websiteUuid);
|
||||
}
|
||||
|
||||
return client
|
||||
.$transaction([
|
||||
client.pageview.deleteMany({
|
||||
where: { session: { website: { user_id } } },
|
||||
where: { session: { website: { userId } } },
|
||||
}),
|
||||
client.event_data.deleteMany({
|
||||
where: { event: { session: { website: { user_id } } } },
|
||||
client.eventData.deleteMany({
|
||||
where: { event: { session: { website: { userId } } } },
|
||||
}),
|
||||
client.event.deleteMany({
|
||||
where: { session: { website: { user_id } } },
|
||||
where: { session: { website: { userId } } },
|
||||
}),
|
||||
client.session.deleteMany({
|
||||
where: { website: { user_id } },
|
||||
where: { website: { userId } },
|
||||
}),
|
||||
client.website.deleteMany({
|
||||
where: { user_id },
|
||||
where: { userId },
|
||||
}),
|
||||
client.account.delete({
|
||||
where: {
|
||||
user_id,
|
||||
id: userId,
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getAccountById(user_id) {
|
||||
export async function getAccountById(userId) {
|
||||
return prisma.client.account.findUnique({
|
||||
where: {
|
||||
user_id,
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ import prisma from 'lib/prisma';
|
|||
export async function getAccounts() {
|
||||
return prisma.client.account.findMany({
|
||||
orderBy: [
|
||||
{ is_admin: 'desc' },
|
||||
{ isAdmin: 'desc' },
|
||||
{
|
||||
username: 'asc',
|
||||
},
|
||||
],
|
||||
select: {
|
||||
user_id: true,
|
||||
id: true,
|
||||
username: true,
|
||||
is_admin: true,
|
||||
created_at: true,
|
||||
updated_at: true,
|
||||
isAdmin: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function updateAccount(user_id, data) {
|
||||
export async function updateAccount(userId, data) {
|
||||
return prisma.client.account.update({
|
||||
where: {
|
||||
user_id,
|
||||
id: userId,
|
||||
},
|
||||
data,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import redis from 'lib/redis';
|
||||
|
||||
export async function createWebsite(user_id, data) {
|
||||
export async function createWebsite(userId, data) {
|
||||
return prisma.client.website
|
||||
.create({
|
||||
data: {
|
||||
account: {
|
||||
connect: {
|
||||
user_id,
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
...data,
|
||||
|
|
@ -15,7 +15,7 @@ export async function createWebsite(user_id, data) {
|
|||
})
|
||||
.then(async res => {
|
||||
if (redis.client && res) {
|
||||
await redis.client.set(`website:${res.website_uuid}`, res.website_id);
|
||||
await redis.client.set(`website:${res.websiteUuid}`, res.id);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -2,30 +2,30 @@ import prisma from 'lib/prisma';
|
|||
import redis, { DELETED } from 'lib/redis';
|
||||
import { getWebsiteById } from 'queries';
|
||||
|
||||
export async function deleteWebsite(website_id) {
|
||||
export async function deleteWebsite(websiteId) {
|
||||
const { client, transaction } = prisma;
|
||||
|
||||
const { website_uuid } = await getWebsiteById(website_id);
|
||||
const { websiteUuid } = await getWebsiteById(websiteId);
|
||||
|
||||
return transaction([
|
||||
client.pageview.deleteMany({
|
||||
where: { session: { website: { website_id } } },
|
||||
where: { session: { website: { id: websiteId } } },
|
||||
}),
|
||||
client.event_data.deleteMany({
|
||||
where: { event: { session: { website: { website_id } } } },
|
||||
client.eventData.deleteMany({
|
||||
where: { event: { session: { website: { id: websiteId } } } },
|
||||
}),
|
||||
client.event.deleteMany({
|
||||
where: { session: { website: { website_id } } },
|
||||
where: { session: { website: { id: websiteId } } },
|
||||
}),
|
||||
client.session.deleteMany({
|
||||
where: { website: { website_id } },
|
||||
where: { website: { id: websiteId } },
|
||||
}),
|
||||
client.website.delete({
|
||||
where: { website_id },
|
||||
where: { id: websiteId },
|
||||
}),
|
||||
]).then(async res => {
|
||||
if (redis.client) {
|
||||
await redis.client.set(`website:${website_uuid}`, DELETED);
|
||||
await redis.client.set(`website:${websiteUuid}`, DELETED);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ export async function getAllWebsites() {
|
|||
let data = await prisma.client.website.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
user_id: 'asc',
|
||||
userId: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'asc',
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getUserWebsites(user_id) {
|
||||
export async function getUserWebsites(userId) {
|
||||
return prisma.client.website.findMany({
|
||||
where: {
|
||||
user_id,
|
||||
userId,
|
||||
},
|
||||
orderBy: {
|
||||
name: 'asc',
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getWebsiteById(website_id) {
|
||||
export async function getWebsiteById(websiteId) {
|
||||
return prisma.client.website.findUnique({
|
||||
where: {
|
||||
website_id,
|
||||
id: websiteId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getWebsiteByShareId(share_id) {
|
||||
export async function getWebsiteByShareId(shareId) {
|
||||
return prisma.client.website.findUnique({
|
||||
where: {
|
||||
share_id,
|
||||
shareId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import redis from 'lib/redis';
|
||||
|
||||
export async function getWebsiteByUuid(website_uuid) {
|
||||
export async function getWebsiteByUuid(websiteUuid) {
|
||||
return prisma.client.website
|
||||
.findUnique({
|
||||
where: {
|
||||
website_uuid,
|
||||
websiteUuid,
|
||||
},
|
||||
})
|
||||
.then(async res => {
|
||||
if (redis.client && res) {
|
||||
await redis.client.set(`website:${res.website_uuid}`, res.website_id);
|
||||
await redis.client.set(`website:${res.websiteUuid}`, res.id);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function resetWebsite(website_id) {
|
||||
export async function resetWebsite(websiteId) {
|
||||
const { client, transaction } = prisma;
|
||||
|
||||
return transaction([
|
||||
client.pageview.deleteMany({
|
||||
where: { session: { website: { website_id } } },
|
||||
where: { session: { website: { id: websiteId } } },
|
||||
}),
|
||||
client.event_data.deleteMany({
|
||||
where: { event: { session: { website: { website_id } } } },
|
||||
client.eventData.deleteMany({
|
||||
where: { event: { session: { website: { id: websiteId } } } },
|
||||
}),
|
||||
client.event.deleteMany({
|
||||
where: { session: { website: { website_id } } },
|
||||
where: { session: { website: { id: websiteId } } },
|
||||
}),
|
||||
client.session.deleteMany({
|
||||
where: { website: { website_id } },
|
||||
where: { website: { id: websiteId } },
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue