mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
use uuid
This commit is contained in:
parent
246e4e5f4f
commit
17041efaae
73 changed files with 491 additions and 874 deletions
|
|
@ -1,7 +0,0 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function createAccount(data) {
|
||||
return prisma.client.account.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getAccount(where) {
|
||||
return prisma.client.account.findUnique({
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function updateAccount(data, where) {
|
||||
return prisma.client.account.update({
|
||||
where,
|
||||
data,
|
||||
});
|
||||
}
|
||||
7
queries/admin/user/createUser.js
Normal file
7
queries/admin/user/createUser.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function createUser(data) {
|
||||
return prisma.client.user.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
|
@ -1,18 +1,17 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import redis, { DELETED } from 'lib/redis';
|
||||
|
||||
export async function deleteAccount(userId) {
|
||||
export async function deleteUser(userId) {
|
||||
const { client } = prisma;
|
||||
|
||||
const websites = await client.website.findMany({
|
||||
where: { userId },
|
||||
select: { websiteUuid: true },
|
||||
});
|
||||
|
||||
let websiteUuids = [];
|
||||
let websiteIds = [];
|
||||
|
||||
if (websites.length > 0) {
|
||||
websiteUuids = websites.map(a => a.websiteUuid);
|
||||
websiteIds = websites.map(a => a.id);
|
||||
}
|
||||
|
||||
return client
|
||||
|
|
@ -32,7 +31,7 @@ export async function deleteAccount(userId) {
|
|||
client.website.deleteMany({
|
||||
where: { userId },
|
||||
}),
|
||||
client.account.delete({
|
||||
client.user.delete({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
|
|
@ -40,8 +39,8 @@ export async function deleteAccount(userId) {
|
|||
])
|
||||
.then(async res => {
|
||||
if (redis.enabled) {
|
||||
for (let i = 0; i < websiteUuids.length; i++) {
|
||||
await redis.set(`website:${websiteUuids[i]}`, DELETED);
|
||||
for (let i = 0; i < websiteIds.length; i++) {
|
||||
await redis.set(`website:${websiteIds[i]}`, DELETED);
|
||||
}
|
||||
}
|
||||
|
||||
7
queries/admin/user/getUser.js
Normal file
7
queries/admin/user/getUser.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getUser(where) {
|
||||
return prisma.client.user.findUnique({
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getAccounts() {
|
||||
return prisma.client.account.findMany({
|
||||
export async function getUsers() {
|
||||
return prisma.client.user.findMany({
|
||||
orderBy: [
|
||||
{ isAdmin: 'desc' },
|
||||
{
|
||||
|
|
@ -13,8 +13,6 @@ export async function getAccounts() {
|
|||
username: true,
|
||||
isAdmin: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
accountUuid: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
8
queries/admin/user/updateUser.js
Normal file
8
queries/admin/user/updateUser.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function updateUser(data, where) {
|
||||
return prisma.client.user.update({
|
||||
where,
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 }));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 } },
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue