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 {prisma} from "@/lib/api/db";
|
||||||
import { LinkRequestQuery, Sort } from "@/types/global";
|
import {LinkRequestQuery, Sort} from "@/types/global";
|
||||||
|
import * as process from "process";
|
||||||
|
|
||||||
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));
|
||||||
console.log(query);
|
console.log(query);
|
||||||
|
|
||||||
|
const POSTGRES_IS_ENABLED = process.env.DATABASE_URL.startsWith("postgresql");
|
||||||
// Sorting logic
|
// Sorting logic
|
||||||
let order: any;
|
let order: any;
|
||||||
if (query.sort === Sort.DateNewestFirst)
|
if (query.sort === Sort.DateNewestFirst)
|
||||||
|
@ -58,7 +60,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: {
|
||||||
|
@ -66,6 +68,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
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -74,6 +77,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
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -82,6 +86,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
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -97,10 +102,11 @@ export default async function getLink(userId: number, body: string) {
|
||||||
query.searchQuery && query.searchFilter?.tags
|
query.searchQuery && query.searchFilter?.tags
|
||||||
? {
|
? {
|
||||||
contains: query.searchQuery,
|
contains: query.searchQuery,
|
||||||
|
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
OR: [
|
OR: [
|
||||||
{ ownerId: userId }, // Tags owned by the user
|
{ownerId: userId}, // Tags owned by the user
|
||||||
{
|
{
|
||||||
links: {
|
links: {
|
||||||
some: {
|
some: {
|
||||||
|
@ -110,6 +116,7 @@ export default async function getLink(userId: number, body: string) {
|
||||||
query.searchFilter?.tags
|
query.searchFilter?.tags
|
||||||
? query.searchQuery
|
? query.searchQuery
|
||||||
: undefined,
|
: undefined,
|
||||||
|
mode: POSTGRES_IS_ENABLED ? "insensitive" : undefined
|
||||||
},
|
},
|
||||||
collection: {
|
collection: {
|
||||||
members: {
|
members: {
|
||||||
|
@ -132,8 +139,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 || {
|
||||||
|
@ -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 {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "sqlite"
|
||||||
url = env("DATABASE_URL")
|
url = env("DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,11 +56,11 @@ model User {
|
||||||
|
|
||||||
collectionsJoined UsersAndCollections[]
|
collectionsJoined UsersAndCollections[]
|
||||||
isPrivate Boolean @default(false)
|
isPrivate Boolean @default(false)
|
||||||
whitelistedUsers whitelistedUser[]
|
whitelistedUsers WhitelistedUser[]
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
}
|
}
|
||||||
|
|
||||||
model whitelistedUser {
|
model WhitelistedUser {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
|
|
||||||
username String @default("")
|
username String @default("")
|
||||||
|
|
Ŝarĝante…
Reference in New Issue