mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
Refactored queries.
This commit is contained in:
parent
18e36aa7b3
commit
b16f5cc067
67 changed files with 523 additions and 576 deletions
|
|
@ -1,39 +1,30 @@
|
|||
import { Prisma, Report } from '@prisma/client';
|
||||
import prisma from 'lib/prisma';
|
||||
import { FilterResult, ReportSearchFilter } from 'lib/types';
|
||||
import ReportFindUniqueArgs = Prisma.ReportFindUniqueArgs;
|
||||
import ReportFindManyArgs = Prisma.ReportFindManyArgs;
|
||||
|
||||
export async function createReport(data: Prisma.ReportUncheckedCreateInput): Promise<Report> {
|
||||
return prisma.client.report.create({ data });
|
||||
async function findReport(criteria: ReportFindUniqueArgs) {
|
||||
return prisma.client.report.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getReportById(reportId: string): Promise<Report> {
|
||||
return prisma.client.report.findUnique({
|
||||
export async function getReport(reportId: string): Promise<Report> {
|
||||
return findReport({
|
||||
where: {
|
||||
id: reportId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateReport(
|
||||
reportId: string,
|
||||
data: Prisma.ReportUpdateInput,
|
||||
): Promise<Report> {
|
||||
return prisma.client.report.update({ where: { id: reportId }, data });
|
||||
}
|
||||
|
||||
export async function deleteReport(reportId: string): Promise<Report> {
|
||||
return prisma.client.report.delete({ where: { id: reportId } });
|
||||
}
|
||||
|
||||
export async function getReports(
|
||||
params: ReportSearchFilter,
|
||||
options?: { include?: Prisma.ReportInclude },
|
||||
criteria: ReportFindManyArgs,
|
||||
filters: ReportSearchFilter = {},
|
||||
): Promise<FilterResult<Report[]>> {
|
||||
const { query, userId, websiteId } = params;
|
||||
|
||||
const mode = prisma.getQueryMode();
|
||||
const { query, userId, websiteId } = filters;
|
||||
|
||||
const where: Prisma.ReportWhereInput = {
|
||||
...criteria.where,
|
||||
userId,
|
||||
websiteId,
|
||||
AND: [
|
||||
|
|
@ -93,32 +84,18 @@ export async function getReports(
|
|||
],
|
||||
};
|
||||
|
||||
const [pageFilters, pageInfo] = prisma.getPageFilters(params);
|
||||
|
||||
const reports = await prisma.client.report.findMany({
|
||||
where,
|
||||
...pageFilters,
|
||||
...(options?.include && { include: options.include }),
|
||||
});
|
||||
|
||||
const count = await prisma.client.report.count({
|
||||
where,
|
||||
});
|
||||
|
||||
return {
|
||||
data: reports,
|
||||
count,
|
||||
...pageInfo,
|
||||
};
|
||||
return prisma.pagedQuery('report', { where }, filters);
|
||||
}
|
||||
|
||||
export async function getReportsByUserId(
|
||||
export async function getUserReports(
|
||||
userId: string,
|
||||
filter?: ReportSearchFilter,
|
||||
filters?: ReportSearchFilter,
|
||||
): Promise<FilterResult<Report[]>> {
|
||||
return getReports(
|
||||
{ userId, ...filter },
|
||||
{
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
include: {
|
||||
website: {
|
||||
select: {
|
||||
|
|
@ -128,12 +105,35 @@ export async function getReportsByUserId(
|
|||
},
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getReportsByWebsiteId(
|
||||
export async function getWebsiteReports(
|
||||
websiteId: string,
|
||||
filter: ReportSearchFilter,
|
||||
filters: ReportSearchFilter = {},
|
||||
): Promise<FilterResult<Report[]>> {
|
||||
return getReports({ websiteId, ...filter });
|
||||
return getReports(
|
||||
{
|
||||
where: {
|
||||
websiteId,
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createReport(data: Prisma.ReportUncheckedCreateInput): Promise<Report> {
|
||||
return prisma.client.report.create({ data });
|
||||
}
|
||||
|
||||
export async function updateReport(
|
||||
reportId: string,
|
||||
data: Prisma.ReportUpdateInput,
|
||||
): Promise<Report> {
|
||||
return prisma.client.report.update({ where: { id: reportId }, data });
|
||||
}
|
||||
|
||||
export async function deleteReport(reportId: string): Promise<Report> {
|
||||
return prisma.client.report.delete({ where: { id: reportId } });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,29 +3,109 @@ import { ROLES } from 'lib/constants';
|
|||
import { uuid } from 'lib/crypto';
|
||||
import prisma from 'lib/prisma';
|
||||
import { FilterResult, TeamSearchFilter } from 'lib/types';
|
||||
import TeamFindManyArgs = Prisma.TeamFindManyArgs;
|
||||
|
||||
export interface GetTeamOptions {
|
||||
includeTeamUser?: boolean;
|
||||
export async function findTeam(criteria: Prisma.TeamFindFirstArgs): Promise<Team> {
|
||||
return prisma.client.team.findFirst(criteria);
|
||||
}
|
||||
|
||||
async function getTeam(where: Prisma.TeamWhereInput, options: GetTeamOptions = {}): Promise<Team> {
|
||||
const { includeTeamUser = false } = options;
|
||||
const { client } = prisma;
|
||||
export async function getTeam(teamId: string, options: { includeMembers?: boolean } = {}) {
|
||||
const { includeMembers } = options;
|
||||
|
||||
return client.team.findFirst({
|
||||
where,
|
||||
include: {
|
||||
teamUser: includeTeamUser,
|
||||
return findTeam({
|
||||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
...(includeMembers && { include: { teamUser: true } }),
|
||||
});
|
||||
}
|
||||
|
||||
export function getTeamById(teamId: string, options: GetTeamOptions = {}) {
|
||||
return getTeam({ id: teamId }, options);
|
||||
export async function getTeams(
|
||||
criteria: TeamFindManyArgs,
|
||||
filters: TeamSearchFilter = {},
|
||||
): Promise<FilterResult<Team[]>> {
|
||||
const mode = prisma.getQueryMode();
|
||||
const { userId, query } = filters;
|
||||
|
||||
const where: Prisma.TeamWhereInput = {
|
||||
...criteria.where,
|
||||
...(userId && {
|
||||
teamUser: {
|
||||
some: { userId },
|
||||
},
|
||||
}),
|
||||
...(query && {
|
||||
AND: {
|
||||
OR: [
|
||||
{
|
||||
name: {
|
||||
startsWith: query,
|
||||
mode,
|
||||
},
|
||||
},
|
||||
{
|
||||
teamUser: {
|
||||
some: {
|
||||
role: ROLES.teamOwner,
|
||||
user: {
|
||||
username: {
|
||||
startsWith: query,
|
||||
mode,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
return prisma.pagedQuery<TeamFindManyArgs>(
|
||||
'team',
|
||||
{
|
||||
...criteria,
|
||||
where,
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export function getTeamByAccessCode(accessCode: string, options: GetTeamOptions = {}) {
|
||||
return getTeam({ accessCode }, options);
|
||||
export async function getUserTeams(userId: string, filters: TeamSearchFilter = {}) {
|
||||
return getTeams(
|
||||
{
|
||||
where: {
|
||||
teamUser: {
|
||||
some: { userId },
|
||||
},
|
||||
},
|
||||
include: {
|
||||
teamUser: {
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
_count: {
|
||||
select: {
|
||||
website: {
|
||||
where: { deletedAt: null },
|
||||
},
|
||||
teamUser: {
|
||||
where: {
|
||||
user: { deletedAt: null },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createTeam(data: Prisma.TeamCreateInput, userId: string): Promise<any> {
|
||||
|
|
@ -93,94 +173,3 @@ export async function deleteTeam(
|
|||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
export async function getTeams(
|
||||
filters: TeamSearchFilter,
|
||||
options?: { include?: Prisma.TeamInclude },
|
||||
): Promise<FilterResult<Team[]>> {
|
||||
const { userId, query } = filters;
|
||||
const mode = prisma.getQueryMode();
|
||||
const { client } = prisma;
|
||||
|
||||
const where: Prisma.TeamWhereInput = {
|
||||
...(userId && {
|
||||
teamUser: {
|
||||
some: { userId },
|
||||
},
|
||||
}),
|
||||
...(query && {
|
||||
AND: {
|
||||
OR: [
|
||||
{
|
||||
name: { startsWith: query, mode },
|
||||
},
|
||||
{
|
||||
teamUser: {
|
||||
some: {
|
||||
role: ROLES.teamOwner,
|
||||
user: {
|
||||
username: {
|
||||
startsWith: query,
|
||||
mode,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const [pageFilters, getParameters] = prisma.getPageFilters({
|
||||
orderBy: 'name',
|
||||
...filters,
|
||||
});
|
||||
|
||||
const teams = await client.team.findMany({
|
||||
where: {
|
||||
...where,
|
||||
},
|
||||
...pageFilters,
|
||||
...(options?.include && { include: options?.include }),
|
||||
});
|
||||
|
||||
const count = await client.team.count({ where });
|
||||
|
||||
return { data: teams, count, ...getParameters };
|
||||
}
|
||||
|
||||
export async function getTeamsByUserId(
|
||||
userId: string,
|
||||
filter?: TeamSearchFilter,
|
||||
): Promise<FilterResult<Team[]>> {
|
||||
return getTeams(
|
||||
{ userId, ...filter },
|
||||
{
|
||||
include: {
|
||||
teamUser: {
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
_count: {
|
||||
select: {
|
||||
website: {
|
||||
where: { deletedAt: null },
|
||||
},
|
||||
teamUser: {
|
||||
where: {
|
||||
user: { deletedAt: null },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
import { Prisma, TeamUser } from '@prisma/client';
|
||||
import { TeamUser } from '@prisma/client';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import prisma from 'lib/prisma';
|
||||
|
||||
export async function getTeamUserById(teamUserId: string): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.findUnique({
|
||||
where: {
|
||||
id: teamUserId,
|
||||
},
|
||||
});
|
||||
}
|
||||
import { FilterResult, TeamUserSearchFilter } from 'lib/types';
|
||||
|
||||
export async function getTeamUser(teamId: string, userId: string): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.findFirst({
|
||||
|
|
@ -21,20 +14,25 @@ export async function getTeamUser(teamId: string, userId: string): Promise<TeamU
|
|||
|
||||
export async function getTeamUsers(
|
||||
teamId: string,
|
||||
): Promise<(TeamUser & { user: { id: string; username: string } })[]> {
|
||||
return prisma.client.teamUser.findMany({
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
filters?: TeamUserSearchFilter,
|
||||
): Promise<FilterResult<TeamUser[]>> {
|
||||
return prisma.pagedQuery(
|
||||
'teamUser',
|
||||
{
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createTeamUser(
|
||||
|
|
@ -52,18 +50,6 @@ export async function createTeamUser(
|
|||
});
|
||||
}
|
||||
|
||||
export async function updateTeamUser(
|
||||
teamUserId: string,
|
||||
data: Prisma.TeamUserUpdateInput,
|
||||
): Promise<TeamUser> {
|
||||
return prisma.client.teamUser.update({
|
||||
where: {
|
||||
id: teamUserId,
|
||||
},
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteTeamUser(teamId: string, userId: string): Promise<TeamUser> {
|
||||
const { client } = prisma;
|
||||
|
||||
|
|
@ -74,15 +60,3 @@ export async function deleteTeamUser(teamId: string, userId: string): Promise<Te
|
|||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteTeamUserByUserId(
|
||||
userId: string,
|
||||
teamId: string,
|
||||
): Promise<Prisma.BatchPayload> {
|
||||
return prisma.client.teamUser.deleteMany({
|
||||
where: {
|
||||
userId,
|
||||
teamId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,24 +4,25 @@ import { ROLES } from 'lib/constants';
|
|||
import prisma from 'lib/prisma';
|
||||
import { FilterResult, Role, User, UserSearchFilter } from 'lib/types';
|
||||
import { getRandomChars } from 'next-basics';
|
||||
import UserFindManyArgs = Prisma.UserFindManyArgs;
|
||||
|
||||
export interface GetUserOptions {
|
||||
includePassword?: boolean;
|
||||
showDeleted?: boolean;
|
||||
}
|
||||
|
||||
async function getUser(
|
||||
where: Prisma.UserWhereUniqueInput,
|
||||
async function findUser(
|
||||
criteria: Prisma.UserFindUniqueArgs,
|
||||
options: GetUserOptions = {},
|
||||
): Promise<User> {
|
||||
const { includePassword = false, showDeleted = false } = options;
|
||||
|
||||
if (showDeleted) {
|
||||
where.deletedAt = null;
|
||||
}
|
||||
|
||||
return prisma.client.user.findUnique({
|
||||
where,
|
||||
...criteria,
|
||||
where: {
|
||||
...criteria.where,
|
||||
...(showDeleted && { delatedAt: null }),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
|
|
@ -32,19 +33,26 @@ async function getUser(
|
|||
});
|
||||
}
|
||||
|
||||
export async function getUserById(id: string, options: GetUserOptions = {}) {
|
||||
return getUser({ id }, options);
|
||||
export async function getUser(userId: string, options: GetUserOptions = {}) {
|
||||
return findUser(
|
||||
{
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getUserByUsername(username: string, options: GetUserOptions = {}) {
|
||||
return getUser({ username }, options);
|
||||
return findUser({ where: { username } }, options);
|
||||
}
|
||||
|
||||
export async function getUsers(
|
||||
params: UserSearchFilter,
|
||||
options?: { include?: Prisma.UserInclude },
|
||||
criteria: UserFindManyArgs,
|
||||
filters?: UserSearchFilter,
|
||||
): Promise<FilterResult<User[]>> {
|
||||
const { teamId, query } = params;
|
||||
const { teamId, query } = filters;
|
||||
const mode = prisma.getQueryMode();
|
||||
|
||||
const where: Prisma.UserWhereInput = {
|
||||
|
|
@ -67,49 +75,19 @@ export async function getUsers(
|
|||
],
|
||||
},
|
||||
}),
|
||||
deletedAt: null,
|
||||
};
|
||||
|
||||
const [pageFilters, getParameters] = prisma.getPageFilters({
|
||||
orderBy: 'createdAt',
|
||||
sortDescending: true,
|
||||
...params,
|
||||
});
|
||||
|
||||
const users = await prisma.client.user
|
||||
.findMany({
|
||||
where: {
|
||||
...where,
|
||||
deletedAt: null,
|
||||
},
|
||||
...pageFilters,
|
||||
...(options?.include && { include: options.include }),
|
||||
})
|
||||
.then((a: { [x: string]: any; password: any }[]) => {
|
||||
return a.map(({ password, ...rest }) => rest);
|
||||
});
|
||||
|
||||
const count = await prisma.client.user.count({
|
||||
where: {
|
||||
...where,
|
||||
deletedAt: null,
|
||||
},
|
||||
});
|
||||
|
||||
return { data: users as any, count, ...getParameters };
|
||||
}
|
||||
|
||||
export async function getUsersByTeamId(teamId: string, filter?: UserSearchFilter) {
|
||||
return getUsers(
|
||||
{ teamId, ...filter },
|
||||
return prisma.pagedQuery(
|
||||
'user',
|
||||
{
|
||||
include: {
|
||||
teamUser: {
|
||||
select: {
|
||||
teamId: true,
|
||||
role: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
...criteria,
|
||||
where,
|
||||
},
|
||||
{
|
||||
orderBy: 'createdAt',
|
||||
sortDescending: true,
|
||||
...filters,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,29 +2,37 @@ import { Prisma, Website } from '@prisma/client';
|
|||
import cache from 'lib/cache';
|
||||
import prisma from 'lib/prisma';
|
||||
import { FilterResult, WebsiteSearchFilter } from 'lib/types';
|
||||
import WebsiteFindManyArgs = Prisma.WebsiteFindManyArgs;
|
||||
|
||||
async function getWebsite(where: Prisma.WebsiteWhereUniqueInput): Promise<Website> {
|
||||
return prisma.client.website.findUnique({
|
||||
where,
|
||||
async function findWebsite(criteria: Prisma.WebsiteFindManyArgs): Promise<Website> {
|
||||
return prisma.client.website.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getWebsite(websiteId: string) {
|
||||
return findWebsite({
|
||||
where: {
|
||||
id: websiteId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getWebsiteById(id: string) {
|
||||
return getWebsite({ id });
|
||||
}
|
||||
|
||||
export async function getWebsiteByShareId(shareId: string) {
|
||||
return getWebsite({ shareId });
|
||||
export async function getSharedWebsite(shareId: string) {
|
||||
return findWebsite({
|
||||
where: {
|
||||
shareId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getWebsites(
|
||||
criteria: WebsiteFindManyArgs,
|
||||
filters: WebsiteSearchFilter,
|
||||
options?: { include?: Prisma.WebsiteInclude },
|
||||
): Promise<FilterResult<Website[]>> {
|
||||
const { userId, teamId, query } = filters;
|
||||
const mode = prisma.getQueryMode();
|
||||
|
||||
const where: Prisma.WebsiteWhereInput = {
|
||||
...criteria.where,
|
||||
AND: [
|
||||
{
|
||||
OR: [
|
||||
|
|
@ -47,34 +55,29 @@ export async function getWebsites(
|
|||
: [],
|
||||
},
|
||||
],
|
||||
deletedAt: null,
|
||||
};
|
||||
|
||||
const [pageFilters, getParameters] = prisma.getPageFilters({
|
||||
orderBy: 'name',
|
||||
...filters,
|
||||
});
|
||||
|
||||
const websites = await prisma.client.website.findMany({
|
||||
where: {
|
||||
...where,
|
||||
deletedAt: null,
|
||||
},
|
||||
...pageFilters,
|
||||
...(options?.include && { include: options.include }),
|
||||
});
|
||||
|
||||
const count = await prisma.client.website.count({ where: { ...where, deletedAt: null } });
|
||||
|
||||
return { data: websites, count, ...getParameters };
|
||||
return prisma.pagedQuery('website', { where }, filters);
|
||||
}
|
||||
|
||||
export async function getWebsitesByUserId(
|
||||
export async function getAllWebsites(userId: string) {
|
||||
return prisma.client.website.findMany({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getUserWebsites(
|
||||
userId: string,
|
||||
filters?: WebsiteSearchFilter,
|
||||
): Promise<FilterResult<Website[]>> {
|
||||
return getWebsites(
|
||||
{ userId, ...filters },
|
||||
{
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
|
|
@ -84,19 +87,22 @@ export async function getWebsitesByUserId(
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
orderBy: 'name',
|
||||
...filters,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function getWebsitesByTeamId(
|
||||
export async function getTeamWebsites(
|
||||
teamId: string,
|
||||
filters?: WebsiteSearchFilter,
|
||||
): Promise<FilterResult<Website[]>> {
|
||||
return getWebsites(
|
||||
{
|
||||
teamId,
|
||||
...filters,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
|
|
@ -106,80 +112,10 @@ export async function getWebsitesByTeamId(
|
|||
},
|
||||
},
|
||||
},
|
||||
filters,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getUserWebsites(
|
||||
userId: string,
|
||||
options?: { includeTeams: boolean },
|
||||
): Promise<Website[]> {
|
||||
const { rawQuery } = prisma;
|
||||
|
||||
if (options?.includeTeams) {
|
||||
const websites = await rawQuery(
|
||||
`
|
||||
select
|
||||
website_id as "id",
|
||||
name,
|
||||
domain,
|
||||
share_id as "shareId",
|
||||
reset_at as "resetAt",
|
||||
user_id as "userId",
|
||||
created_at as "createdAt",
|
||||
updated_at as "updatedAt",
|
||||
deleted_at as "deletedAt",
|
||||
null as "teamId",
|
||||
null as "teamName"
|
||||
from website
|
||||
where user_id = {{userId::uuid}}
|
||||
and deleted_at is null
|
||||
union
|
||||
select
|
||||
w.website_id as "id",
|
||||
w.name,
|
||||
w.domain,
|
||||
w.share_id as "shareId",
|
||||
w.reset_at as "resetAt",
|
||||
w.user_id as "userId",
|
||||
w.created_at as "createdAt",
|
||||
w.updated_at as "updatedAt",
|
||||
w.deleted_at as "deletedAt",
|
||||
t.team_id as "teamId",
|
||||
t.name as "teamName"
|
||||
from website w
|
||||
inner join team_website tw
|
||||
on tw.website_id = w.website_id
|
||||
inner join team t
|
||||
on t.team_id = tw.team_id
|
||||
inner join team_user tu
|
||||
on tu.team_id = tw.team_id
|
||||
where tu.user_id = {{userId::uuid}}
|
||||
and w.deleted_at is null
|
||||
`,
|
||||
{ userId },
|
||||
);
|
||||
|
||||
return websites.reduce((arr, item) => {
|
||||
if (!arr.find(({ id }) => id === item.id)) {
|
||||
return arr.concat(item);
|
||||
}
|
||||
return arr;
|
||||
}, []);
|
||||
}
|
||||
|
||||
return prisma.client.website.findMany({
|
||||
where: {
|
||||
userId,
|
||||
deletedAt: null,
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
name: 'asc',
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
export async function createWebsite(
|
||||
data: Prisma.WebsiteCreateInput | Prisma.WebsiteUncheckedCreateInput,
|
||||
): Promise<Website> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue