mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 23:27:12 +01:00
Initial Typescript models.
This commit is contained in:
parent
04e9f06e93
commit
0aaba8cbd1
74 changed files with 1144 additions and 768 deletions
|
|
@ -1,7 +1,16 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import { Website } from '@prisma/client';
|
||||
import cache from 'lib/cache';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function createWebsite(userId, data) {
|
||||
export async function createWebsite(
|
||||
userId: string,
|
||||
data: {
|
||||
id: string;
|
||||
name: string;
|
||||
domain: string;
|
||||
shareId?: string;
|
||||
},
|
||||
): Promise<Website> {
|
||||
return prisma.client.website
|
||||
.create({
|
||||
data: {
|
||||
|
|
@ -1,22 +1,25 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import cache from 'lib/cache';
|
||||
import { Prisma, Website } from '@prisma/client';
|
||||
|
||||
export async function deleteWebsite(id) {
|
||||
export async function deleteWebsite(
|
||||
websiteId: string,
|
||||
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
||||
const { client, transaction } = prisma;
|
||||
|
||||
return transaction([
|
||||
client.websiteEvent.deleteMany({
|
||||
where: { websiteId: id },
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.session.deleteMany({
|
||||
where: { websiteId: id },
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.website.delete({
|
||||
where: { id },
|
||||
where: { id: websiteId },
|
||||
}),
|
||||
]).then(async data => {
|
||||
if (cache.enabled) {
|
||||
await cache.deleteWebsite(id);
|
||||
await cache.deleteWebsite(websiteId);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getAllWebsites() {
|
||||
let data = await prisma.client.website.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
userId: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'asc',
|
||||
},
|
||||
],
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return data.map(i => ({ ...i, user: i.user.username }));
|
||||
}
|
||||
24
queries/admin/website/getAllWebsites.ts
Normal file
24
queries/admin/website/getAllWebsites.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { Website } from '@prisma/client';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getAllWebsites(): Promise<(Website & { user: string })[]> {
|
||||
return await prisma.client.website
|
||||
.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
userId: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'asc',
|
||||
},
|
||||
],
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
.then(data => data.map(i => ({ ...i, user: i.user.username })));
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import { Website } from '@prisma/client';
|
||||
|
||||
export async function getUserWebsites(userId) {
|
||||
export async function getUserWebsites(userId): Promise<Website[]> {
|
||||
return prisma.client.website.findMany({
|
||||
where: {
|
||||
userId,
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getWebsite(where) {
|
||||
return prisma.client.website.findUnique({
|
||||
where,
|
||||
});
|
||||
}
|
||||
8
queries/admin/website/getWebsite.ts
Normal file
8
queries/admin/website/getWebsite.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import prisma from 'lib/prisma';
|
||||
import { Prisma, Website } from '@prisma/client';
|
||||
|
||||
export async function getWebsite(where: Prisma.WebsiteWhereUniqueInput): Promise<Website> {
|
||||
return prisma.client.website.findUnique({
|
||||
where,
|
||||
});
|
||||
}
|
||||
|
|
@ -1,20 +1,23 @@
|
|||
import { Prisma, Website } from '@prisma/client';
|
||||
import cache from 'lib/cache';
|
||||
import prisma from 'lib/prisma';
|
||||
import { getWebsite } from 'queries';
|
||||
import cache from 'lib/cache';
|
||||
|
||||
export async function resetWebsite(id) {
|
||||
export async function resetWebsite(
|
||||
websiteId,
|
||||
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
||||
const { client, transaction } = prisma;
|
||||
|
||||
const { revId } = await getWebsite({ id });
|
||||
const { revId } = await getWebsite({ id: websiteId });
|
||||
|
||||
return transaction([
|
||||
client.websiteEvent.deleteMany({
|
||||
where: { websiteId: id },
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.session.deleteMany({
|
||||
where: { websiteId: id },
|
||||
where: { websiteId },
|
||||
}),
|
||||
client.website.update({ where: { id }, data: { revId: revId + 1 } }),
|
||||
client.website.update({ where: { id: websiteId }, data: { revId: revId + 1 } }),
|
||||
]).then(async data => {
|
||||
if (cache.enabled) {
|
||||
await cache.storeWebsite(data[2]);
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function updateWebsite(id, data) {
|
||||
return prisma.client.website.update({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
data,
|
||||
});
|
||||
}
|
||||
11
queries/admin/website/updateWebsite.ts
Normal file
11
queries/admin/website/updateWebsite.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { Prisma, Website } from '@prisma/client';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function updateWebsite(websiteId, data: Prisma.WebsiteUpdateInput): Promise<Website> {
|
||||
return prisma.client.website.update({
|
||||
where: {
|
||||
id: websiteId,
|
||||
},
|
||||
data,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue