updated migration file
This commit is contained in:
parent
2177f12b9b
commit
a56b8e24da
|
@ -1,5 +1,5 @@
|
||||||
import {prisma} from "@/lib/api/db";
|
import { prisma } from "@/lib/api/db";
|
||||||
import {LinkRequestQuery, Sort} from "@/types/global";
|
import { LinkRequestQuery, Sort } from "@/types/global";
|
||||||
|
|
||||||
export default async function getLink(userId: number, body: string) {
|
export default async function getLink(userId: number, body: string) {
|
||||||
const query: LinkRequestQuery = JSON.parse(decodeURIComponent(body));
|
const query: LinkRequestQuery = JSON.parse(decodeURIComponent(body));
|
||||||
|
@ -38,8 +38,8 @@ export default async function getLink(userId: number, body: string) {
|
||||||
skip: query.cursor ? 1 : undefined,
|
skip: query.cursor ? 1 : undefined,
|
||||||
cursor: query.cursor
|
cursor: query.cursor
|
||||||
? {
|
? {
|
||||||
id: query.cursor,
|
id: query.cursor,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
where: {
|
where: {
|
||||||
collection: {
|
collection: {
|
||||||
|
@ -59,7 +59,7 @@ export default async function getLink(userId: number, body: string) {
|
||||||
},
|
},
|
||||||
[query.searchQuery ? "OR" : "AND"]: [
|
[query.searchQuery ? "OR" : "AND"]: [
|
||||||
{
|
{
|
||||||
pinnedBy: query.pinnedOnly ? {some: {id: userId}} : undefined,
|
pinnedBy: query.pinnedOnly ? { some: { id: userId } } : undefined,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: {
|
name: {
|
||||||
|
@ -67,7 +67,7 @@ export default async function getLink(userId: number, body: string) {
|
||||||
query.searchQuery && query.searchFilter?.name
|
query.searchQuery && query.searchFilter?.name
|
||||||
? query.searchQuery
|
? query.searchQuery
|
||||||
: undefined,
|
: undefined,
|
||||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -76,7 +76,7 @@ export default async function getLink(userId: number, body: string) {
|
||||||
query.searchQuery && query.searchFilter?.url
|
query.searchQuery && query.searchFilter?.url
|
||||||
? query.searchQuery
|
? query.searchQuery
|
||||||
: undefined,
|
: undefined,
|
||||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -85,7 +85,7 @@ export default async function getLink(userId: number, body: string) {
|
||||||
query.searchQuery && query.searchFilter?.description
|
query.searchQuery && query.searchFilter?.description
|
||||||
? query.searchQuery
|
? query.searchQuery
|
||||||
: undefined,
|
: undefined,
|
||||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -93,44 +93,48 @@ export default async function getLink(userId: number, body: string) {
|
||||||
query.searchQuery && !query.searchFilter?.tags
|
query.searchQuery && !query.searchFilter?.tags
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
some: query.tagId
|
some: query.tagId
|
||||||
? {
|
? {
|
||||||
// If tagId was defined, filter by tag
|
// If tagId was defined, filter by tag
|
||||||
id: query.tagId,
|
id: query.tagId,
|
||||||
name:
|
name:
|
||||||
query.searchQuery && query.searchFilter?.tags
|
query.searchQuery && query.searchFilter?.tags
|
||||||
? {
|
? {
|
||||||
contains: query.searchQuery,
|
contains: query.searchQuery,
|
||||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
mode: POSTGRES_IS_ENABLED
|
||||||
}
|
? "insensitive"
|
||||||
: undefined,
|
|
||||||
OR: [
|
|
||||||
{ownerId: userId}, // Tags owned by the user
|
|
||||||
{
|
|
||||||
links: {
|
|
||||||
some: {
|
|
||||||
name: {
|
|
||||||
contains:
|
|
||||||
query.searchQuery &&
|
|
||||||
query.searchFilter?.tags
|
|
||||||
? query.searchQuery
|
|
||||||
: undefined,
|
: undefined,
|
||||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
}
|
||||||
},
|
: undefined,
|
||||||
collection: {
|
OR: [
|
||||||
members: {
|
{ ownerId: userId }, // Tags owned by the user
|
||||||
some: {
|
{
|
||||||
userId, // Tags from collections where the user is a member
|
links: {
|
||||||
|
some: {
|
||||||
|
name: {
|
||||||
|
contains:
|
||||||
|
query.searchQuery &&
|
||||||
|
query.searchFilter?.tags
|
||||||
|
? query.searchQuery
|
||||||
|
: undefined,
|
||||||
|
mode: POSTGRES_IS_ENABLED
|
||||||
|
? "insensitive"
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
collection: {
|
||||||
|
members: {
|
||||||
|
some: {
|
||||||
|
userId, // Tags from collections where the user is a member
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
},
|
}
|
||||||
],
|
: undefined,
|
||||||
}
|
},
|
||||||
: undefined,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -138,8 +142,8 @@ export default async function getLink(userId: number, body: string) {
|
||||||
tags: true,
|
tags: true,
|
||||||
collection: true,
|
collection: true,
|
||||||
pinnedBy: {
|
pinnedBy: {
|
||||||
where: {id: userId},
|
where: { id: userId },
|
||||||
select: {id: true},
|
select: { id: true },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
orderBy: order || {
|
orderBy: order || {
|
||||||
|
@ -147,5 +151,5 @@ export default async function getLink(userId: number, body: string) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return {response: links, status: 200};
|
return { response: links, status: 200 };
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `whitelistedUsers` on the `User` table. All the data in the column will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "User" DROP COLUMN "whitelistedUsers";
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "WhitelistedUser" (
|
||||||
|
"id" SERIAL NOT NULL,
|
||||||
|
"username" TEXT NOT NULL DEFAULT '',
|
||||||
|
"userId" INTEGER,
|
||||||
|
|
||||||
|
CONSTRAINT "WhitelistedUser_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "WhitelistedUser" ADD CONSTRAINT "WhitelistedUser_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
Ŝarĝante…
Reference in New Issue