add mode insensitive in case we are using postgresql + rename table
This commit is contained in:
parent
22093c0c29
commit
895ef8e60f
|
@ -1,10 +1,12 @@
|
|||
import { prisma } from "@/lib/api/db";
|
||||
import { LinkRequestQuery, Sort } from "@/types/global";
|
||||
import {prisma} from "@/lib/api/db";
|
||||
import {LinkRequestQuery, Sort} from "@/types/global";
|
||||
import * as process from "process";
|
||||
|
||||
export default async function getLink(userId: number, body: string) {
|
||||
const query: LinkRequestQuery = JSON.parse(decodeURIComponent(body));
|
||||
console.log(query);
|
||||
|
||||
const POSTGRES_IS_ENABLED = process.env.DATABASE_URL.startsWith("postgresql");
|
||||
// Sorting logic
|
||||
let order: any;
|
||||
if (query.sort === Sort.DateNewestFirst)
|
||||
|
@ -58,7 +60,7 @@ export default async function getLink(userId: number, body: string) {
|
|||
},
|
||||
[query.searchQuery ? "OR" : "AND"]: [
|
||||
{
|
||||
pinnedBy: query.pinnedOnly ? { some: { id: userId } } : undefined,
|
||||
pinnedBy: query.pinnedOnly ? {some: {id: userId}} : undefined,
|
||||
},
|
||||
{
|
||||
name: {
|
||||
|
@ -66,6 +68,7 @@ export default async function getLink(userId: number, body: string) {
|
|||
query.searchQuery && query.searchFilter?.name
|
||||
? query.searchQuery
|
||||
: undefined,
|
||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -74,6 +77,7 @@ export default async function getLink(userId: number, body: string) {
|
|||
query.searchQuery && query.searchFilter?.url
|
||||
? query.searchQuery
|
||||
: undefined,
|
||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -82,6 +86,7 @@ export default async function getLink(userId: number, body: string) {
|
|||
query.searchQuery && query.searchFilter?.description
|
||||
? query.searchQuery
|
||||
: undefined,
|
||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -97,10 +102,11 @@ export default async function getLink(userId: number, body: string) {
|
|||
query.searchQuery && query.searchFilter?.tags
|
||||
? {
|
||||
contains: query.searchQuery,
|
||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
||||
}
|
||||
: undefined,
|
||||
OR: [
|
||||
{ ownerId: userId }, // Tags owned by the user
|
||||
{ownerId: userId}, // Tags owned by the user
|
||||
{
|
||||
links: {
|
||||
some: {
|
||||
|
@ -110,6 +116,7 @@ export default async function getLink(userId: number, body: string) {
|
|||
query.searchFilter?.tags
|
||||
? query.searchQuery
|
||||
: undefined,
|
||||
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
||||
},
|
||||
collection: {
|
||||
members: {
|
||||
|
@ -132,8 +139,8 @@ export default async function getLink(userId: number, body: string) {
|
|||
tags: true,
|
||||
collection: true,
|
||||
pinnedBy: {
|
||||
where: { id: userId },
|
||||
select: { id: true },
|
||||
where: {id: userId},
|
||||
select: {id: true},
|
||||
},
|
||||
},
|
||||
orderBy: order || {
|
||||
|
@ -141,5 +148,5 @@ export default async function getLink(userId: number, body: string) {
|
|||
},
|
||||
});
|
||||
|
||||
return { response: links, status: 200 };
|
||||
return {response: links, status: 200};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ generator client {
|
|||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
|
@ -56,11 +56,11 @@ model User {
|
|||
|
||||
collectionsJoined UsersAndCollections[]
|
||||
isPrivate Boolean @default(false)
|
||||
whitelistedUsers whitelistedUser[]
|
||||
whitelistedUsers WhitelistedUser[]
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
|
||||
model whitelistedUser {
|
||||
model WhitelistedUser {
|
||||
id Int @id @default(autoincrement())
|
||||
|
||||
username String @default("")
|
||||
|
|
Ŝarĝante…
Reference in New Issue