new kysely pickTable utils
This commit is contained in:
parent
9d03d845d2
commit
2e316f274b
39 changed files with 387 additions and 39 deletions
10
apps/infoalloggi/package-lock.json
generated
10
apps/infoalloggi/package-lock.json
generated
|
|
@ -50,7 +50,7 @@
|
|||
"framer-motion": "^12.38.0",
|
||||
"frimousse": "^0.3.0",
|
||||
"jose": "^6.0.12",
|
||||
"kysely": "^0.28.17",
|
||||
"kysely": "^0.29.0",
|
||||
"kysely-plugin-serialize": "^0.8.2",
|
||||
"leaflet": "^1.9.4",
|
||||
"leaflet-defaulticon-compatibility": "^0.1.2",
|
||||
|
|
@ -9743,13 +9743,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/kysely": {
|
||||
"version": "0.28.17",
|
||||
"resolved": "https://registry.npmjs.org/kysely/-/kysely-0.28.17.tgz",
|
||||
"integrity": "sha512-nbD8lB9EB3wNdMhOCdx5Li8DxnLbvKByylRLcJ1h+4SkrowVeECAyZlyiKMThF7xFdRz0jSQ2MoJr+wXux2y0Q==",
|
||||
"version": "0.29.0",
|
||||
"resolved": "https://registry.npmjs.org/kysely/-/kysely-0.29.0.tgz",
|
||||
"integrity": "sha512-LrQfPUeTW7MXbMvT62moEMnpMTuj9TO3lqjCeLKjM975PJ4Alrl/43f2tlDX7xOsNptKgH4LSNGwIbXwEkLg4g==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
"node": ">=22.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/kysely-plugin-serialize": {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
"framer-motion": "^12.38.0",
|
||||
"frimousse": "^0.3.0",
|
||||
"jose": "^6.0.12",
|
||||
"kysely": "^0.28.17",
|
||||
"kysely": "^0.29.0",
|
||||
"kysely-plugin-serialize": "^0.8.2",
|
||||
"leaflet": "^1.9.4",
|
||||
"leaflet-defaulticon-compatibility": "^0.1.2",
|
||||
|
|
@ -160,4 +160,4 @@
|
|||
"axios": "^1.16.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -60,6 +60,7 @@ export const annunciRouter = createTRPCRouter({
|
|||
)
|
||||
.query(async ({ input }) => {
|
||||
return await db
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.selectAll()
|
||||
.where("id", "=", input.id)
|
||||
|
|
@ -147,6 +148,7 @@ export const annunciRouter = createTRPCRouter({
|
|||
/**Used for cron job */
|
||||
checkAnnunci: apiProcedure.query(async () => {
|
||||
const hasAnnunci = await db
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.select("id")
|
||||
.where("stato", "=", "Attivo")
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
if (input.targetMsgId) {
|
||||
// If a targetMsgId is provided, we want to fetch messages around that message
|
||||
const msgs = await db
|
||||
.$pickTables<"messages" | "messages_attachments" | "users">()
|
||||
.selectFrom("messages")
|
||||
.innerJoin("users", "users.id", "messages.sender")
|
||||
.select((eb) => [
|
||||
|
|
@ -151,6 +152,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
.orderBy("messages.messageid", "asc")
|
||||
.execute();
|
||||
const prevCheck = await db
|
||||
.$pickTables<"messages">()
|
||||
.selectFrom("messages")
|
||||
.where("chatid", "=", input.chatId)
|
||||
.where("messageid", "<", input.targetMsgId)
|
||||
|
|
@ -168,6 +170,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
const cursor = input.cursor;
|
||||
|
||||
let qry = db
|
||||
.$pickTables<"messages" | "messages_attachments" | "users">()
|
||||
.selectFrom("messages")
|
||||
.innerJoin("users", "users.id", "messages.sender")
|
||||
.select((eb) => [
|
||||
|
|
@ -266,6 +269,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
)
|
||||
.mutation(async ({ input }) => {
|
||||
const newMessage = await db
|
||||
.$pickTables<"messages">()
|
||||
.insertInto("messages")
|
||||
.values({
|
||||
chatid: input.chatId,
|
||||
|
|
@ -282,6 +286,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
let hasAttachments = false;
|
||||
if (input.attachments.length > 0) {
|
||||
const newAttachments = await db
|
||||
.$pickTables<"messages_attachments">()
|
||||
.insertInto("messages_attachments")
|
||||
.values(
|
||||
input.attachments.map(({ userStorageId }) => ({
|
||||
|
|
@ -294,6 +299,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
hasAttachments = newAttachments.length > 0;
|
||||
}
|
||||
const rs = await db
|
||||
.$pickTables<"messages" | "users">()
|
||||
.selectFrom("messages")
|
||||
.innerJoin("users", "users.id", "messages.sender")
|
||||
.select([
|
||||
|
|
@ -307,6 +313,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
.executeTakeFirst();
|
||||
|
||||
const userInfos = await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.select([
|
||||
"nome as sender_nome",
|
||||
|
|
@ -355,6 +362,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"messages">()
|
||||
.deleteFrom("messages")
|
||||
.where("messageid", "=", input.messageId)
|
||||
.execute();
|
||||
|
|
@ -532,6 +540,7 @@ export const chatSSERouter = createTRPCRouter({
|
|||
})() ?? null;
|
||||
|
||||
const newMessagesSinceLast = await db
|
||||
.$pickTables<"messages" | "messages_attachments" | "users">()
|
||||
.selectFrom("messages")
|
||||
.innerJoin("users", "users.id", "messages.sender")
|
||||
.select((eb) => [
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ export const comunicazioniRouter = createTRPCRouter({
|
|||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
const ordine = await db
|
||||
.$pickTables<"ordini" | "users" | "prezziario">()
|
||||
.selectFrom("ordini")
|
||||
.selectAll("ordini")
|
||||
.innerJoin("users", "users.id", "ordini.userid")
|
||||
|
|
@ -242,6 +243,7 @@ export const comunicazioniRouter = createTRPCRouter({
|
|||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
const user = await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.selectAll()
|
||||
.where("id", "=", input.userId)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ export const etichetteRouter = createTRPCRouter({
|
|||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"user_etichette">()
|
||||
.insertInto("user_etichette")
|
||||
.values({
|
||||
etichettaId: input.etichettaId,
|
||||
|
|
@ -86,6 +87,7 @@ export const etichetteRouter = createTRPCRouter({
|
|||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"user_etichette">()
|
||||
.deleteFrom("user_etichette")
|
||||
.where("etichettaId", "=", input.etichettaId)
|
||||
.where("userId", "=", input.userId)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ export const intrestsRouter = createTRPCRouter({
|
|||
userId,
|
||||
});
|
||||
const annuncio = await db
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.select(["id", "codice", "titolo_it"])
|
||||
.where("id", "=", input.annuncioId)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export const pagamentiRouter = createTRPCRouter({
|
|||
.query(async ({ input }) => {
|
||||
try {
|
||||
const ordine = await db
|
||||
.$pickTables<"ordini">()
|
||||
.selectFrom("ordini")
|
||||
.selectAll("ordini")
|
||||
.where("ordini.intent_id", "=", input.pIntentId)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ export const statsRouter = createTRPCRouter({
|
|||
const userCount =
|
||||
(
|
||||
await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.select((eb) => [eb.fn.count<number>("id").as("count")])
|
||||
.executeTakeFirst()
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ export const usersRouter = createTRPCRouter({
|
|||
|
||||
getUsers: adminProcedure.query(async () => {
|
||||
return await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.selectAll()
|
||||
.orderBy("id", "desc")
|
||||
|
|
@ -39,6 +40,7 @@ export const usersRouter = createTRPCRouter({
|
|||
}),
|
||||
getAdmins: adminProcedure.query(async () => {
|
||||
return await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.selectAll()
|
||||
.where("isAdmin", "=", true)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export const getAnnunciListHandler = async (): Promise<
|
|||
> => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.select([
|
||||
"id",
|
||||
|
|
@ -52,6 +53,7 @@ export const getAnnunciListHandler = async (): Promise<
|
|||
export const getCodici_AnnunciHandler = async (): Promise<string[]> => {
|
||||
try {
|
||||
const codici = await db
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.select("codice")
|
||||
.where("annunci.web", "=", true)
|
||||
|
|
@ -119,6 +121,7 @@ export const getAnnuncioData = async ({
|
|||
}): Promise<Result<AnnuncioData, getAnnuncioDataError>> => {
|
||||
try {
|
||||
const annuncio = await db
|
||||
.$pickTables<"annunci" | "images_refs" | "videos_refs">()
|
||||
.selectFrom("annunci")
|
||||
.select([
|
||||
"anno",
|
||||
|
|
@ -196,6 +199,7 @@ export const getAnnunciById_rawImgUrls = async ({
|
|||
}): Promise<AnnunciWithMedia | null> => {
|
||||
try {
|
||||
const annuncio = await db
|
||||
.$pickTables<"annunci" | "images_refs" | "videos_refs">()
|
||||
.selectFrom("annunci")
|
||||
.selectAll()
|
||||
.select((_eb) => [withImages(), withVideos()])
|
||||
|
|
@ -238,6 +242,7 @@ export const get_AnnunciPositionsHandler = async ({
|
|||
}): Promise<AnnuncioRicercaWPosition[]> => {
|
||||
try {
|
||||
let query = db
|
||||
.$pickTables<"annunci" | "images_refs" | "videos_refs">()
|
||||
.selectFrom("annunci")
|
||||
.select((_eb) => [
|
||||
"id",
|
||||
|
|
@ -342,6 +347,7 @@ export const getAnnunciRicerca = async ({
|
|||
}): Promise<AnnuncioRicerca[]> => {
|
||||
try {
|
||||
let query = db
|
||||
.$pickTables<"annunci" | "images_refs" | "videos_refs">()
|
||||
.selectFrom("annunci")
|
||||
.select((_eb) => [
|
||||
"id",
|
||||
|
|
@ -417,6 +423,7 @@ export const getAnnunciRicerca = async ({
|
|||
export const getOptions_AnnunciHandler = async () => {
|
||||
try {
|
||||
const comuni = await db
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.select(["comune", "tipo", "consegna", "prezzo"])
|
||||
.where("web", "=", true)
|
||||
|
|
@ -459,6 +466,7 @@ export const editAnnuncioHandler = async ({
|
|||
}) => {
|
||||
try {
|
||||
const annuncio = await db
|
||||
.$pickTables<"annunci">()
|
||||
.updateTable("annunci")
|
||||
.set({
|
||||
...data,
|
||||
|
|
@ -488,6 +496,7 @@ export const getProprietarioDataHandler = async ({
|
|||
}) => {
|
||||
try {
|
||||
const opened_at = await db
|
||||
.$pickTables<"servizio_annunci">()
|
||||
.selectFrom("servizio_annunci")
|
||||
.select("open_contatti_at")
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -498,6 +507,7 @@ export const getProprietarioDataHandler = async ({
|
|||
}
|
||||
|
||||
const propData = await db
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.select([
|
||||
"codice",
|
||||
|
|
@ -541,10 +551,18 @@ export const removeAnnuncioMedia = async ({
|
|||
}: ImgToRemove | VideoToRemove) => {
|
||||
try {
|
||||
if (type === "img") {
|
||||
await db.deleteFrom("images_refs").where("img", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"images_refs">()
|
||||
.deleteFrom("images_refs")
|
||||
.where("img", "=", id)
|
||||
.execute();
|
||||
}
|
||||
if (type === "video") {
|
||||
await db.deleteFrom("videos_refs").where("video", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"videos_refs">()
|
||||
.deleteFrom("videos_refs")
|
||||
.where("video", "=", id)
|
||||
.execute();
|
||||
}
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -559,6 +577,7 @@ export const getAnnunciSchedaData = async (
|
|||
): Promise<AnnuncioTemplateData> => {
|
||||
try {
|
||||
const data = await db
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.select([
|
||||
"codice",
|
||||
|
|
|
|||
|
|
@ -299,6 +299,7 @@ export const passwordChange = async ({
|
|||
const salt = generateSalt();
|
||||
const hashedPassword = await hashPassword(newpassword, salt);
|
||||
await db
|
||||
.$pickTables<"users">()
|
||||
.updateTable("users")
|
||||
.set({
|
||||
password: hashedPassword,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { db } from "../db";
|
|||
export const getComuni = async () => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"comuni">()
|
||||
.selectFrom("comuni")
|
||||
.selectAll()
|
||||
.orderBy("nome", "asc")
|
||||
|
|
@ -40,7 +41,12 @@ export const editComune = async ({
|
|||
data: ComuniUpdate;
|
||||
}) => {
|
||||
try {
|
||||
await db.updateTable("comuni").set(data).where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"comuni">()
|
||||
.updateTable("comuni")
|
||||
.set(data)
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -52,7 +58,11 @@ export const editComune = async ({
|
|||
export const createComune = async (data: NewComuni) => {
|
||||
const { id, ...rest } = data;
|
||||
try {
|
||||
await db.insertInto("comuni").values(rest).execute();
|
||||
await db
|
||||
.$pickTables<"comuni">()
|
||||
.insertInto("comuni")
|
||||
.values(rest)
|
||||
.execute();
|
||||
return "ok";
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -64,7 +74,11 @@ export const createComune = async (data: NewComuni) => {
|
|||
|
||||
export const deleteComune = async (id: ComuniId) => {
|
||||
try {
|
||||
await db.deleteFrom("comuni").where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"comuni">()
|
||||
.deleteFrom("comuni")
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return "ok";
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -76,7 +90,11 @@ export const deleteComune = async (id: ComuniId) => {
|
|||
|
||||
export const getProvincie = async () => {
|
||||
try {
|
||||
return await db.selectFrom("provincie").selectAll().execute();
|
||||
return await db
|
||||
.$pickTables<"provincie">()
|
||||
.selectFrom("provincie")
|
||||
.selectAll()
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -93,7 +111,12 @@ export const editProvincia = async ({
|
|||
data: ProvincieUpdate;
|
||||
}) => {
|
||||
try {
|
||||
await db.updateTable("provincie").set(data).where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"provincie">()
|
||||
.updateTable("provincie")
|
||||
.set(data)
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return "ok";
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -106,7 +129,11 @@ export const editProvincia = async ({
|
|||
export const createProvincia = async (data: NewProvincie) => {
|
||||
const { id, ...rest } = data;
|
||||
try {
|
||||
await db.insertInto("provincie").values(rest).execute();
|
||||
await db
|
||||
.$pickTables<"provincie">()
|
||||
.insertInto("provincie")
|
||||
.values(rest)
|
||||
.execute();
|
||||
return "ok";
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -118,7 +145,11 @@ export const createProvincia = async (data: NewProvincie) => {
|
|||
|
||||
export const deleteProvincia = async (id: ProvincieId) => {
|
||||
try {
|
||||
await db.deleteFrom("provincie").where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"provincie">()
|
||||
.deleteFrom("provincie")
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return "ok";
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -131,6 +162,7 @@ export const deleteProvincia = async (id: ProvincieId) => {
|
|||
export const getNazioni = async () => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"nazioni">()
|
||||
.selectFrom("nazioni")
|
||||
.selectAll()
|
||||
.orderBy(sql`nome = 'ITALIA'`, "desc")
|
||||
|
|
@ -152,7 +184,12 @@ export const editNazione = async ({
|
|||
data: NazioniUpdate;
|
||||
}) => {
|
||||
try {
|
||||
await db.updateTable("nazioni").set(data).where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"nazioni">()
|
||||
.updateTable("nazioni")
|
||||
.set(data)
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return "ok";
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -165,7 +202,11 @@ export const editNazione = async ({
|
|||
export const createNazione = async (data: NewNazioni) => {
|
||||
const { id, ...rest } = data;
|
||||
try {
|
||||
await db.insertInto("nazioni").values(rest).execute();
|
||||
await db
|
||||
.$pickTables<"nazioni">()
|
||||
.insertInto("nazioni")
|
||||
.values(rest)
|
||||
.execute();
|
||||
return "ok";
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -177,7 +218,11 @@ export const createNazione = async (data: NewNazioni) => {
|
|||
|
||||
export const deleteNazione = async (id: NazioniId) => {
|
||||
try {
|
||||
await db.deleteFrom("nazioni").where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"nazioni">()
|
||||
.deleteFrom("nazioni")
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return "ok";
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ export type ActiveChatsType = Pick<Chats, "chatid" | "created_at"> &
|
|||
|
||||
export const getActiveInfos = async (): Promise<ActiveChatsType[]> => {
|
||||
const chats = await db
|
||||
.$pickTables<
|
||||
"messages" | "chats" | "users" | "etichette" | "chats_etichette"
|
||||
>()
|
||||
.selectFrom("chats")
|
||||
.innerJoin("users", "users.id", "chats.user_ref")
|
||||
.select((eb) => [
|
||||
|
|
@ -86,6 +89,7 @@ export const getChatInfo = async ({
|
|||
export const getChatByUser = async ({ userId }: { userId: UsersId }) => {
|
||||
try {
|
||||
const chat = await db
|
||||
.$pickTables<"chats">()
|
||||
.selectFrom("chats")
|
||||
.select(["chatid", getUserInfo()])
|
||||
.where("chats.user_ref", "=", userId)
|
||||
|
|
@ -98,6 +102,7 @@ export const getChatByUser = async ({ userId }: { userId: UsersId }) => {
|
|||
});
|
||||
|
||||
const chat = await db
|
||||
.$pickTables<"chats">()
|
||||
.selectFrom("chats")
|
||||
.select(["chatid", getUserInfo()])
|
||||
.where("chats.user_ref", "=", userId)
|
||||
|
|
@ -124,6 +129,7 @@ export const deleteChatHandler = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"chats">()
|
||||
.deleteFrom("chats")
|
||||
.where("chats.chatid", "=", chatId)
|
||||
.returning("chatid")
|
||||
|
|
@ -143,6 +149,7 @@ export const getUserByChatHandler = async ({
|
|||
chatId: ChatsChatid;
|
||||
}) => {
|
||||
const chat = await db
|
||||
.$pickTables<"chats">()
|
||||
.selectFrom("chats")
|
||||
.select(["chatid", "created_at", "user_ref", getUserInfo()])
|
||||
.where("chats.chatid", "=", chatId)
|
||||
|
|
@ -162,6 +169,7 @@ export const getChatByUserIdHandler = async ({
|
|||
userId: UsersId;
|
||||
}) => {
|
||||
const chat = await db
|
||||
.$pickTables<"chats">()
|
||||
.selectFrom("chats")
|
||||
.select("chatid")
|
||||
.where("chats.user_ref", "=", userId)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ import type { Querier } from "~/server/db";
|
|||
|
||||
export const getAllEtichette = async ({ db }: { db: Querier }) => {
|
||||
try {
|
||||
return await db.selectFrom("etichette").selectAll().execute();
|
||||
return await db
|
||||
.$pickTables<"etichette">()
|
||||
.selectFrom("etichette")
|
||||
.selectAll()
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -25,6 +29,7 @@ export const addEtichetta = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"etichette">()
|
||||
.insertInto("etichette")
|
||||
.returning("id_etichetta")
|
||||
.values({ color_hex, title })
|
||||
|
|
@ -50,6 +55,7 @@ export const updateEtichetta = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"etichette">()
|
||||
.updateTable("etichette")
|
||||
.returning("id_etichetta")
|
||||
.set({ color_hex, title })
|
||||
|
|
@ -72,6 +78,7 @@ export const removeEtichetta = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"etichette">()
|
||||
.deleteFrom("etichette")
|
||||
.where("id_etichetta", "=", etichettaid)
|
||||
.execute();
|
||||
|
|
@ -93,6 +100,7 @@ export const getChatEtichette = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"etichette" | "chats_etichette">()
|
||||
.selectFrom("etichette")
|
||||
.innerJoin(
|
||||
"chats_etichette",
|
||||
|
|
@ -125,6 +133,7 @@ export const addChatEtichette = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"chats_etichette">()
|
||||
.insertInto("chats_etichette")
|
||||
.returning("chatid")
|
||||
.values({ chatid, etichettaid })
|
||||
|
|
@ -149,6 +158,7 @@ export const removeChatEtichette = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"chats_etichette">()
|
||||
.deleteFrom("chats_etichette")
|
||||
.where("chatid", "=", chatid)
|
||||
.where("etichettaid", "=", etichettaid)
|
||||
|
|
|
|||
|
|
@ -115,7 +115,11 @@ type NewEventQueueProps = Override<NewEventQueue, { data: EventDataTypes }>;
|
|||
|
||||
export const addEventToQueue = async (data: NewEventQueueProps) => {
|
||||
try {
|
||||
await db.insertInto("event_queue").values(data).execute();
|
||||
await db
|
||||
.$pickTables<"event_queue">()
|
||||
.insertInto("event_queue")
|
||||
.values(data)
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -127,6 +131,7 @@ export const addEventToQueue = async (data: NewEventQueueProps) => {
|
|||
const getEventsFromQueue = async () => {
|
||||
try {
|
||||
const events = await db
|
||||
.$pickTables<"event_queue">()
|
||||
.selectFrom("event_queue")
|
||||
.selectAll()
|
||||
.where("event_queue.isActive", "=", true)
|
||||
|
|
@ -200,6 +205,7 @@ export const processEvents = async () => {
|
|||
export const getEmailQueue = async () => {
|
||||
try {
|
||||
const events = await db
|
||||
.$pickTables<"event_queue" | "users">()
|
||||
.selectFrom("event_queue")
|
||||
.selectAll("event_queue")
|
||||
.select((eb) => [
|
||||
|
|
@ -227,6 +233,7 @@ export const getEmailQueue = async () => {
|
|||
export const userEmailQueue = async (userId: UsersId) => {
|
||||
try {
|
||||
const events = await db
|
||||
.$pickTables<"event_queue">()
|
||||
.selectFrom("event_queue")
|
||||
.selectAll()
|
||||
.where(sql`data->>'tipo'`, "=", "email")
|
||||
|
|
@ -244,6 +251,7 @@ export const userEmailQueue = async (userId: UsersId) => {
|
|||
export const removeEventFromQueue = async (eventId: EventQueueEventId) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"event_queue">()
|
||||
.deleteFrom("event_queue")
|
||||
.where("event_id", "=", eventId)
|
||||
.execute();
|
||||
|
|
@ -259,6 +267,7 @@ export const removeEventFromQueue = async (eventId: EventQueueEventId) => {
|
|||
export const clearEmailQueue = async () => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"event_queue">()
|
||||
.deleteFrom("event_queue")
|
||||
.where(sql`data->>'tipo'`, "=", "email")
|
||||
.execute();
|
||||
|
|
@ -274,6 +283,7 @@ export const clearEmailQueue = async () => {
|
|||
export const clearUserEmailQueue = async (userId: UsersId) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"event_queue">()
|
||||
.deleteFrom("event_queue")
|
||||
.where(sql`data->>'tipo'`, "=", "email")
|
||||
.where(sql`data->'data'->>'userId'`, "=", userId)
|
||||
|
|
@ -291,6 +301,7 @@ export const clearUserEmailQueue = async (userId: UsersId) => {
|
|||
export const disableUserEmailQueue = async (userId: UsersId) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"event_queue">()
|
||||
.updateTable("event_queue")
|
||||
.set({ isActive: false })
|
||||
.where(sql`data->>'tipo'`, "=", "email")
|
||||
|
|
@ -311,6 +322,7 @@ export const updateEvent = async (
|
|||
) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"event_queue">()
|
||||
.updateTable("event_queue")
|
||||
.set(data)
|
||||
.where("event_id", "=", eventId)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ export const getClientFromCF = async (cf: string) => {
|
|||
export const exportUserToFIC = async (userId: UsersId) => {
|
||||
try {
|
||||
const user = await db
|
||||
.$pickTables<"users" | "users_anagrafica" | "nazioni" | "comuni">()
|
||||
.selectFrom("users")
|
||||
.innerJoin("users_anagrafica", "users_anagrafica.userid", "users.id")
|
||||
.select([
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { db } from "~/server/db";
|
|||
export const EditFlagHandler = async (input: Flags) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"flags">()
|
||||
.updateTable("flags")
|
||||
.set({
|
||||
value: input.value,
|
||||
|
|
@ -21,7 +22,11 @@ export const EditFlagHandler = async (input: Flags) => {
|
|||
};
|
||||
export const GetFlagHandler = async () => {
|
||||
try {
|
||||
return await db.selectFrom("flags").selectAll().execute();
|
||||
return await db
|
||||
.$pickTables<"flags">()
|
||||
.selectFrom("flags")
|
||||
.selectAll()
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -33,6 +38,7 @@ export const GetFlagHandler = async () => {
|
|||
export const GetFlagValueHandler = async (id: string) => {
|
||||
try {
|
||||
const flag = await db
|
||||
.$pickTables<"flags">()
|
||||
.selectFrom("flags")
|
||||
.select("value")
|
||||
.where("id", "=", id as FlagsId)
|
||||
|
|
@ -48,7 +54,11 @@ export const GetFlagValueHandler = async (id: string) => {
|
|||
|
||||
export const RemoveFlagHandler = async (id: FlagsId) => {
|
||||
try {
|
||||
await db.deleteFrom("flags").where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"flags">()
|
||||
.deleteFrom("flags")
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return true;
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -60,6 +70,7 @@ export const RemoveFlagHandler = async (id: FlagsId) => {
|
|||
export const AddFlagHandler = async (input: Flags) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"flags">()
|
||||
.insertInto("flags")
|
||||
.values({
|
||||
id: input.id,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ export async function createInviteToken(email: string) {
|
|||
try {
|
||||
// Store in database
|
||||
await db
|
||||
.$pickTables<"user_invites">()
|
||||
.insertInto("user_invites")
|
||||
.values({
|
||||
email,
|
||||
|
|
@ -142,6 +143,7 @@ async function verifyInviteToken(
|
|||
): Promise<Result<UserInvites, TokenVerErrors>> {
|
||||
try {
|
||||
const invite = await db
|
||||
.$pickTables<"user_invites">()
|
||||
.selectFrom("user_invites")
|
||||
.selectAll("user_invites")
|
||||
.where("token", "=", token)
|
||||
|
|
@ -166,7 +168,11 @@ async function verifyInviteToken(
|
|||
|
||||
async function consumeInviteToken(token: string) {
|
||||
try {
|
||||
await db.deleteFrom("user_invites").where("token", "=", token).execute();
|
||||
await db
|
||||
.$pickTables<"user_invites">()
|
||||
.deleteFrom("user_invites")
|
||||
.where("token", "=", token)
|
||||
.execute();
|
||||
} catch (e) {
|
||||
console.error("Error consuming invite token:", e);
|
||||
throw new TRPCError({
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ export const preparePayment = async (
|
|||
const { servizioId, type } = props;
|
||||
const servizio = await getServizioById(servizioId);
|
||||
const inactiveOrders = await db
|
||||
.$pickTables<"ordini">()
|
||||
.selectFrom("ordini")
|
||||
.selectAll()
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -331,6 +332,7 @@ export const preparePayment = async (
|
|||
const { rinnovoId } = props;
|
||||
|
||||
const ordiniRinnovo = await db
|
||||
.$pickTables<"ordini">()
|
||||
.selectFrom("ordini")
|
||||
.selectAll()
|
||||
.where("rinnovo_id", "=", rinnovoId)
|
||||
|
|
@ -380,6 +382,7 @@ export const preparePayment = async (
|
|||
}
|
||||
// nessun rinnovo preesistente, crearne uno nuovo
|
||||
const rinnovo = await db
|
||||
.$pickTables<"rinnovi">()
|
||||
.selectFrom("rinnovi")
|
||||
.selectAll()
|
||||
.where("id", "=", rinnovoId)
|
||||
|
|
@ -429,6 +432,7 @@ export const preparePayment = async (
|
|||
export const getPagamentoDataForCheckout = async (ordineId: OrdiniOrdineId) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"ordini" | "users" | "prezziario">()
|
||||
.selectFrom("ordini")
|
||||
.select([
|
||||
"ordini.ordine_id",
|
||||
|
|
@ -486,6 +490,7 @@ export const AccontoSolver = async (
|
|||
switch (tipologia) {
|
||||
case tipologiaPosizioneEnum.enum.Transitorio: {
|
||||
const pack = await db
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("isActive", "=", true)
|
||||
|
|
@ -505,6 +510,7 @@ export const AccontoSolver = async (
|
|||
|
||||
case tipologiaPosizioneEnum.enum.Stabile: {
|
||||
const pack = await db
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("isActive", "=", true)
|
||||
|
|
@ -545,6 +551,7 @@ export const SaldoSolver = async ({
|
|||
}
|
||||
|
||||
const pack = await db
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("isActive", "=", true)
|
||||
|
|
@ -563,6 +570,7 @@ export const SaldoSolver = async ({
|
|||
case tipologiaPosizioneEnum.enum.Stabile: {
|
||||
const budget_step = budget > 700 ? 2 : budget > 500 ? 1 : 0;
|
||||
const pack = await db
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("isActive", "=", true)
|
||||
|
|
@ -608,6 +616,7 @@ export const RinnovoSolver = async (
|
|||
const permanenza = rinnovoDurationToPermanenza(decorrenza, scadenza);
|
||||
|
||||
const pack = await db
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("isActive", "=", true)
|
||||
|
|
@ -674,6 +683,7 @@ export const getRicevutaData = async (
|
|||
): Promise<{ title: string; data: RicevutaProps }> => {
|
||||
try {
|
||||
const ordine = await db
|
||||
.$pickTables<"prezziario" | "ordini">()
|
||||
.selectFrom("ordini")
|
||||
.select([
|
||||
"ordini.ordine_id",
|
||||
|
|
@ -693,6 +703,7 @@ export const getRicevutaData = async (
|
|||
);
|
||||
|
||||
const anagrafica = await db
|
||||
.$pickTables<"users" | "users_anagrafica">()
|
||||
.selectFrom("users")
|
||||
.select("users.username")
|
||||
.innerJoin("users_anagrafica", "users_anagrafica.userid", "users.id")
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ export const getDataPerAcquisto = async (servizioId: ServizioServizioId) => {
|
|||
}
|
||||
|
||||
const userData = await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.select([
|
||||
"users.id",
|
||||
|
|
@ -68,6 +69,7 @@ export const getDataPerAcquisto = async (servizioId: ServizioServizioId) => {
|
|||
});
|
||||
}
|
||||
const anagrafica = await db
|
||||
.$pickTables<"users_anagrafica">()
|
||||
.selectFrom("users_anagrafica")
|
||||
.selectAll("users_anagrafica")
|
||||
.where("users_anagrafica.userid", "=", servizio.user_id)
|
||||
|
|
@ -102,6 +104,7 @@ export const processServizioOnboard = async ({
|
|||
await db.transaction().execute(async (tx) => {
|
||||
// Update user and anagrafica data
|
||||
await tx
|
||||
.$pickTables<"users">()
|
||||
.updateTable("users")
|
||||
.set(user)
|
||||
.where("id", "=", userId)
|
||||
|
|
@ -110,6 +113,7 @@ export const processServizioOnboard = async ({
|
|||
const { idanagrafica, ...rest } = anagrafica;
|
||||
if (idanagrafica) {
|
||||
await tx
|
||||
.$pickTables<"users_anagrafica">()
|
||||
.updateTable("users_anagrafica")
|
||||
.set({
|
||||
...rest,
|
||||
|
|
@ -125,6 +129,7 @@ export const processServizioOnboard = async ({
|
|||
);
|
||||
} else {
|
||||
await tx
|
||||
.$pickTables<"users_anagrafica">()
|
||||
.insertInto("users_anagrafica")
|
||||
.values({
|
||||
...rest,
|
||||
|
|
@ -137,6 +142,7 @@ export const processServizioOnboard = async ({
|
|||
}
|
||||
// Update servizio data
|
||||
return await tx
|
||||
.$pickTables<"servizio">()
|
||||
.updateTable("servizio")
|
||||
.set({ ...servizio, onboardOk: true })
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -167,6 +173,7 @@ export const attivaServizio_SaltaPagamentoAcconto = async (
|
|||
try {
|
||||
return await db.transaction().execute(async (tx) => {
|
||||
const ordine = await tx
|
||||
.$pickTables<"ordini" | "users" | "prezziario">()
|
||||
.selectFrom("ordini")
|
||||
.innerJoin("users", "users.id", "ordini.userid")
|
||||
.innerJoin("prezziario", "prezziario.idprezziario", "ordini.packid")
|
||||
|
|
@ -186,6 +193,7 @@ export const attivaServizio_SaltaPagamentoAcconto = async (
|
|||
const user = await getUser({ db: tx, userId: ordine.userId });
|
||||
|
||||
const servizio = await tx
|
||||
.$pickTables<"servizio">()
|
||||
.updateTable("servizio")
|
||||
.set({
|
||||
decorrenza: new Date(),
|
||||
|
|
@ -268,6 +276,7 @@ export const AdminAttivaServizio_Ufficio = async (
|
|||
try {
|
||||
return await db.transaction().execute(async (tx) => {
|
||||
const data = await tx
|
||||
.$pickTables<"users" | "servizio">()
|
||||
.selectFrom("servizio")
|
||||
.select(["servizio.user_id", "servizio.interruzioneDays"])
|
||||
.innerJoin("users", "users.id", "servizio.user_id")
|
||||
|
|
@ -369,6 +378,15 @@ export const getAllServizioAnnunci = async (
|
|||
try {
|
||||
const data = await withParsedDates(
|
||||
db
|
||||
.$pickTables<
|
||||
| "servizio"
|
||||
| "users_anagrafica"
|
||||
| "users_storage"
|
||||
| "servizio_annunci"
|
||||
| "prezziario"
|
||||
| "ordini"
|
||||
| "annunci"
|
||||
>()
|
||||
.selectFrom("servizio")
|
||||
.where("user_id", "=", userId)
|
||||
.leftJoin(
|
||||
|
|
@ -507,6 +525,15 @@ export const getServizioDataById = async (
|
|||
try {
|
||||
const data = await withParsedDates(
|
||||
db
|
||||
.$pickTables<
|
||||
| "users_anagrafica"
|
||||
| "servizio"
|
||||
| "servizio_annunci"
|
||||
| "users_storage"
|
||||
| "annunci"
|
||||
| "ordini"
|
||||
| "prezziario"
|
||||
>()
|
||||
.selectFrom("servizio")
|
||||
.leftJoin(
|
||||
"users_anagrafica",
|
||||
|
|
@ -654,6 +681,7 @@ export const addServizioAnnunci = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"servizio_annunci">()
|
||||
.insertInto("servizio_annunci")
|
||||
.values(
|
||||
annunci.map((annuncio, idx) => ({
|
||||
|
|
@ -682,6 +710,7 @@ export const getAnnunciAvailableToAdd = async (
|
|||
try {
|
||||
return await db.transaction().execute(async (tx) => {
|
||||
const servizioAnnunci = await tx
|
||||
.$pickTables<"servizio_annunci">()
|
||||
.selectFrom("servizio_annunci")
|
||||
.select("annunci_id")
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -689,6 +718,7 @@ export const getAnnunciAvailableToAdd = async (
|
|||
|
||||
const ids = servizioAnnunci.map((item) => item.annunci_id);
|
||||
let qry = tx
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.select(["id", "codice", "titolo_it"])
|
||||
.where("annunci.web", "=", true)
|
||||
|
|
@ -716,6 +746,7 @@ export const SbloccaContatti = async ({
|
|||
}) => {
|
||||
try {
|
||||
const alreadyUnlocked = await db
|
||||
.$pickTables<"servizio_annunci">()
|
||||
.selectFrom("servizio_annunci")
|
||||
.where("servizio_id", "=", servizioId)
|
||||
.where("open_contatti_at", "is not", null)
|
||||
|
|
@ -727,6 +758,7 @@ export const SbloccaContatti = async ({
|
|||
|
||||
const data = await db.transaction().execute(async (tx) => {
|
||||
await tx
|
||||
.$pickTables<"servizio_annunci">()
|
||||
.updateTable("servizio_annunci")
|
||||
.set({
|
||||
open_contatti_at: new Date(),
|
||||
|
|
@ -736,24 +768,28 @@ export const SbloccaContatti = async ({
|
|||
.execute();
|
||||
|
||||
const servizio = await tx
|
||||
.$pickTables<"servizio">()
|
||||
.selectFrom("servizio")
|
||||
.select("user_id")
|
||||
.where("servizio_id", "=", servizioId)
|
||||
.executeTakeFirstOrThrow(() => new Error("Servizio not found"));
|
||||
|
||||
const user = await tx
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.select(["id", "username", "email", "telefono", "comms_enabled"])
|
||||
.where("id", "=", servizio.user_id)
|
||||
.executeTakeFirstOrThrow(() => new Error("User not found"));
|
||||
|
||||
const anagrafica = await tx
|
||||
.$pickTables<"users_anagrafica">()
|
||||
.selectFrom("users_anagrafica")
|
||||
.select("sesso")
|
||||
.where("userid", "=", servizio.user_id)
|
||||
.executeTakeFirstOrThrow(() => new Error("Anagrafica not found"));
|
||||
|
||||
const annuncio = await tx
|
||||
.$pickTables<"annunci">()
|
||||
.selectFrom("annunci")
|
||||
.where("id", "=", annuncioId)
|
||||
.select([
|
||||
|
|
@ -886,6 +922,7 @@ export const interruzioneServizio = async (
|
|||
}
|
||||
|
||||
await db
|
||||
.$pickTables<"servizio">()
|
||||
.updateTable("servizio")
|
||||
.set({
|
||||
isInterrotto: true,
|
||||
|
|
@ -954,6 +991,7 @@ export const InteractionLogicTipologia = async ({
|
|||
return { status: "invalid" as const };
|
||||
}
|
||||
const servizi = await db
|
||||
.$pickTables<"servizio" | "servizio_annunci">()
|
||||
.selectFrom("servizio")
|
||||
.select(["tipologia", "servizio_id"])
|
||||
.where("tipologia", "=", parsedTipologia.data)
|
||||
|
|
@ -1053,6 +1091,7 @@ export const getCompatibileAnnunci = async ({
|
|||
const interests = await GetUserInterests(servizio.user_id);
|
||||
|
||||
let qry = db
|
||||
.$pickTables<"annunci" | "servizio_annunci">()
|
||||
.selectFrom("annunci")
|
||||
.distinctOn("annunci.id")
|
||||
.select((eb) => [
|
||||
|
|
@ -1178,6 +1217,14 @@ export const getRichieste = async (): Promise<RichiesteData[]> => {
|
|||
try {
|
||||
const data = await withParsedDates(
|
||||
db
|
||||
.$pickTables<
|
||||
| "servizio"
|
||||
| "users"
|
||||
| "servizio_annunci"
|
||||
| "annunci"
|
||||
| "ordini"
|
||||
| "prezziario"
|
||||
>()
|
||||
.selectFrom("servizio")
|
||||
.innerJoin("users", "users.id", "servizio.user_id")
|
||||
.select([
|
||||
|
|
@ -1290,6 +1337,7 @@ export const getRichieste = async (): Promise<RichiesteData[]> => {
|
|||
export const getIncrociAnnuncio = async (annuncioId: AnnunciId) => {
|
||||
try {
|
||||
const data = await db
|
||||
.$pickTables<"servizio_annunci" | "users" | "servizio">()
|
||||
.selectFrom("servizio_annunci")
|
||||
.innerJoin(
|
||||
"servizio",
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export const getMultipleWithRelations = async ({
|
|||
}) => {
|
||||
const files = await fetchFiles();
|
||||
const userStorage = await db
|
||||
.$pickTables<"users_storage" | "users">()
|
||||
.selectFrom("users_storage")
|
||||
.selectAll("users_storage")
|
||||
.innerJoin("users", "users.id", "users_storage.userId")
|
||||
|
|
@ -48,6 +49,7 @@ export const retrieveUserFiles = async ({ userId }: { userId: UsersId }) => {
|
|||
try {
|
||||
//all files linked to the user
|
||||
const files = await db
|
||||
.$pickTables<"users_storage">()
|
||||
.selectFrom("users_storage")
|
||||
.select(["storageId", "from_admin"])
|
||||
.where("userId", "=", userId)
|
||||
|
|
@ -58,6 +60,7 @@ export const retrieveUserFiles = async ({ userId }: { userId: UsersId }) => {
|
|||
|
||||
//remove entries in users_storage for files that no longer exist in storage
|
||||
await db
|
||||
.$pickTables<"users_storage">()
|
||||
.deleteFrom("users_storage")
|
||||
.where("userId", "=", userId)
|
||||
.where("storageId", "in", unavailable)
|
||||
|
|
@ -91,6 +94,7 @@ export const retrieveChatMessageFiles = async ({
|
|||
}) => {
|
||||
try {
|
||||
const messageFiles = await db
|
||||
.$pickTables<"messages_attachments" | "users_storage">()
|
||||
.selectFrom("messages_attachments")
|
||||
.innerJoin(
|
||||
"users_storage",
|
||||
|
|
@ -108,6 +112,7 @@ export const retrieveChatMessageFiles = async ({
|
|||
|
||||
//remove entries in users_storage for files that no longer exist in storage
|
||||
await db
|
||||
.$pickTables<"users_storage">()
|
||||
.deleteFrom("users_storage")
|
||||
.where("storageId", "in", unavailable)
|
||||
.execute();
|
||||
|
|
@ -124,6 +129,7 @@ export const retrieveChatMessageFiles = async ({
|
|||
export const getAllWithFromAdmin = async () => {
|
||||
try {
|
||||
const files = await db
|
||||
.$pickTables<"users_storage">()
|
||||
.selectFrom("users_storage")
|
||||
.select(["storageId", "from_admin"])
|
||||
.execute();
|
||||
|
|
@ -149,6 +155,7 @@ export const getAllWithFromAdmin = async () => {
|
|||
export const addUserStorage = async (data: NewUsersStorage) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"users_storage">()
|
||||
.insertInto("users_storage")
|
||||
.values(data)
|
||||
.onConflict((oc) => oc.columns(["userId", "storageId"]).doNothing())
|
||||
|
|
@ -171,6 +178,7 @@ export const deleteUserStorageEntry = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"users_storage">()
|
||||
.deleteFrom("users_storage")
|
||||
.where("userId", "=", userId)
|
||||
.where("storageId", "=", storageId)
|
||||
|
|
@ -191,6 +199,7 @@ export const purgeFileFromUserStorages = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"users_storage">()
|
||||
.deleteFrom("users_storage")
|
||||
.where("storageId", "=", storageId)
|
||||
.execute();
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ export const whIntentCreatedHandler = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"ordini">()
|
||||
.updateTable("ordini")
|
||||
.set({
|
||||
intent_id: pIntentId,
|
||||
|
|
@ -72,6 +73,7 @@ export const whIntentSucceededHandler = async ({
|
|||
|
||||
await db.transaction().execute(async (trx) => {
|
||||
const ordine = await trx
|
||||
.$pickTables<"ordini">()
|
||||
.updateTable("ordini")
|
||||
.set({
|
||||
paid_at: new Date(),
|
||||
|
|
@ -90,6 +92,7 @@ export const whIntentSucceededHandler = async ({
|
|||
const condizioniFilename = `condizioni_contrattuali_${(ordine.paid_at || ordine.created_at).toISOString()}.pdf`;
|
||||
const ricevutaFilename = `ricevuta_cortesia_${(ordine.paid_at || ordine.created_at).toISOString()}.pdf`;
|
||||
const condizioni = await trx
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.select("testo_condizioni")
|
||||
.where("idprezziario", "=", ordine.packid)
|
||||
|
|
@ -102,6 +105,7 @@ export const whIntentSucceededHandler = async ({
|
|||
|
||||
// cleanup ordini non pagati e non attivi per lo stesso utente, stesso tipo e servizio (es. se paga acconto, cancellare altri ordini acconto non pagati)
|
||||
await trx
|
||||
.$pickTables<"ordini">()
|
||||
.deleteFrom("ordini")
|
||||
.where("userid", "=", ordine.userid)
|
||||
.where("isActive", "=", false)
|
||||
|
|
@ -121,6 +125,7 @@ export const whIntentSucceededHandler = async ({
|
|||
}
|
||||
|
||||
const servizio = await trx
|
||||
.$pickTables<"servizio">()
|
||||
.updateTable("servizio")
|
||||
.where("servizio_id", "=", ordine.servizio_id)
|
||||
.set({
|
||||
|
|
@ -204,6 +209,7 @@ export const whIntentSucceededHandler = async ({
|
|||
);
|
||||
}
|
||||
const servizio = await trx
|
||||
.$pickTables<"servizio">()
|
||||
.selectFrom("servizio")
|
||||
.select(["servizio.tipologia"])
|
||||
.where("servizio_id", "=", ordine.servizio_id)
|
||||
|
|
@ -214,6 +220,7 @@ export const whIntentSucceededHandler = async ({
|
|||
});
|
||||
|
||||
await trx
|
||||
.$pickTables<"servizio">()
|
||||
.updateTable("servizio")
|
||||
.where("servizio_id", "=", ordine.servizio_id)
|
||||
.set({
|
||||
|
|
@ -294,6 +301,7 @@ export const whIntentSucceededHandler = async ({
|
|||
}
|
||||
|
||||
await trx
|
||||
.$pickTables<"servizio">()
|
||||
.updateTable("servizio")
|
||||
.where("servizio_id", "=", ordine.servizio_id)
|
||||
.set({
|
||||
|
|
@ -399,6 +407,7 @@ export const whIntentFailedHandler = async ({
|
|||
pIntentId: Ordini["intent_id"];
|
||||
}) => {
|
||||
const userId = await db
|
||||
.$pickTables<"ordini">()
|
||||
.updateTable("ordini")
|
||||
.set({
|
||||
paymentstatus: paymentStatusEnum.enum.failed,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ export const editAccountHandler = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"users">()
|
||||
.updateTable("users")
|
||||
.set({
|
||||
...data,
|
||||
|
|
@ -55,6 +56,7 @@ export const editAnagraficaHandler = async ({
|
|||
}
|
||||
|
||||
return await db
|
||||
.$pickTables<"users_anagrafica">()
|
||||
.insertInto("users_anagrafica")
|
||||
.values({
|
||||
...rest,
|
||||
|
|
@ -77,7 +79,11 @@ export const editAnagraficaHandler = async ({
|
|||
|
||||
export const deleteUserHandler = async (id: UsersId) => {
|
||||
try {
|
||||
await db.deleteFrom("users").where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"users">()
|
||||
.deleteFrom("users")
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return { success: true };
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -90,6 +96,7 @@ export const deleteUserHandler = async (id: UsersId) => {
|
|||
export const blockUserHandler = async (id: UsersId) => {
|
||||
return await db.transaction().execute(async (trx) => {
|
||||
return await trx
|
||||
.$pickTables<"users">()
|
||||
.updateTable("users")
|
||||
.set((eb) => ({
|
||||
isBlocked: eb.not("isBlocked"),
|
||||
|
|
@ -104,6 +111,7 @@ export const blockUserHandler = async (id: UsersId) => {
|
|||
export const getUserHandler = async (id: UsersId) => {
|
||||
try {
|
||||
const user = await db
|
||||
.$pickTables<"users" | "users_anagrafica">()
|
||||
.selectFrom("users")
|
||||
.leftJoin("users_anagrafica", "users_anagrafica.userid", "users.id")
|
||||
.where("id", "=", id)
|
||||
|
|
@ -131,6 +139,7 @@ export type NonNullableUser = {
|
|||
export const getActiveUserWithoutChatHandler = async () => {
|
||||
try {
|
||||
const users = await db
|
||||
.$pickTables<"users" | "chats">()
|
||||
.selectFrom("users")
|
||||
.fullJoin("chats", "chats.user_ref", "users.id")
|
||||
.select(["users.id", "users.username", "users.nome"])
|
||||
|
|
@ -169,6 +178,9 @@ export const getUsersWithChatInfoHandler = async (): Promise<
|
|||
> => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<
|
||||
"users" | "chats" | "etichette" | "chats_etichette" | "user_etichette"
|
||||
>()
|
||||
.selectFrom("users")
|
||||
.select([
|
||||
"users.id",
|
||||
|
|
@ -216,6 +228,7 @@ export const getUsersWithChatInfoHandler = async (): Promise<
|
|||
export const genUserIntestazione = async (userId: UsersId) => {
|
||||
try {
|
||||
const data = await db
|
||||
.$pickTables<"users" | "users_anagrafica">()
|
||||
.selectFrom("users")
|
||||
.innerJoin("users_anagrafica", "users_anagrafica.userid", "users.id")
|
||||
.where("id", "=", userId)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ export type AppuntiData = Omit<Appunti, "appunti_group_id"> & {
|
|||
export const getAppunti = async (): Promise<AppuntiData[]> => {
|
||||
try {
|
||||
const appunti = await db
|
||||
.$pickTables<"appunti" | "appunti_groups" | "users">()
|
||||
.selectFrom("appunti")
|
||||
.select([
|
||||
"appunti.id",
|
||||
|
|
@ -57,7 +58,11 @@ export const getAppunti = async (): Promise<AppuntiData[]> => {
|
|||
|
||||
export const getAppuntiGroups = async (): Promise<AppuntiGroups[]> => {
|
||||
try {
|
||||
return await db.selectFrom("appunti_groups").selectAll().execute();
|
||||
return await db
|
||||
.$pickTables<"appunti_groups">()
|
||||
.selectFrom("appunti_groups")
|
||||
.selectAll()
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -68,7 +73,11 @@ export const getAppuntiGroups = async (): Promise<AppuntiGroups[]> => {
|
|||
|
||||
export const addAppuntiGroup = async (data: NewAppuntiGroups) => {
|
||||
try {
|
||||
await db.insertInto("appunti_groups").values(data).execute();
|
||||
await db
|
||||
.$pickTables<"appunti_groups">()
|
||||
.insertInto("appunti_groups")
|
||||
.values(data)
|
||||
.execute();
|
||||
return { status: "success" };
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -80,7 +89,11 @@ export const addAppuntiGroup = async (data: NewAppuntiGroups) => {
|
|||
|
||||
export const deleteAppuntiGroup = async (id: AppuntiGroupsId) => {
|
||||
try {
|
||||
await db.deleteFrom("appunti_groups").where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"appunti_groups">()
|
||||
.deleteFrom("appunti_groups")
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return { status: "success" };
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -92,7 +105,11 @@ export const deleteAppuntiGroup = async (id: AppuntiGroupsId) => {
|
|||
|
||||
export const addAppunti = async (data: NewAppunti) => {
|
||||
try {
|
||||
await db.insertInto("appunti").values(data).execute();
|
||||
await db
|
||||
.$pickTables<"appunti">()
|
||||
.insertInto("appunti")
|
||||
.values(data)
|
||||
.execute();
|
||||
return { status: "success" };
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -104,7 +121,11 @@ export const addAppunti = async (data: NewAppunti) => {
|
|||
|
||||
export const deleteAppunti = async (id: AppuntiId) => {
|
||||
try {
|
||||
await db.deleteFrom("appunti").where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"appunti">()
|
||||
.deleteFrom("appunti")
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return { status: "success" };
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -116,7 +137,12 @@ export const deleteAppunti = async (id: AppuntiId) => {
|
|||
|
||||
export const updateAppunto = async (id: AppuntiId, data: AppuntiUpdate) => {
|
||||
try {
|
||||
await db.updateTable("appunti").set(data).where("id", "=", id).execute();
|
||||
await db
|
||||
.$pickTables<"appunti">()
|
||||
.updateTable("appunti")
|
||||
.set(data)
|
||||
.where("id", "=", id)
|
||||
.execute();
|
||||
return { status: "success" };
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -136,6 +162,7 @@ export const updateAppunti = async (data: AppuntiData[]) => {
|
|||
for (const item of dataWithPositions) {
|
||||
const { column, username: _username, ...rest } = item;
|
||||
await db
|
||||
.$pickTables<"appunti">()
|
||||
.updateTable("appunti")
|
||||
.set({
|
||||
...rest,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ export const genPasswordResetToken = async ({ id }: { id: UsersId }) => {
|
|||
const newToken = randomBytes(20).toString("hex");
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"users">()
|
||||
.updateTable("users")
|
||||
.set({
|
||||
reset_password_expires: reset_expiry,
|
||||
|
|
@ -36,6 +37,7 @@ export const genPasswordResetToken = async ({ id }: { id: UsersId }) => {
|
|||
export const isTokenValid = async ({ token }: { token: string }) => {
|
||||
try {
|
||||
const user = await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.select("id")
|
||||
.where("reset_password_token", "=", token)
|
||||
|
|
@ -63,6 +65,7 @@ export const resetPasswordFromTokenHandler = async ({
|
|||
}) => {
|
||||
try {
|
||||
const user = await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.select("id")
|
||||
.where("reset_password_token", "=", token)
|
||||
|
|
@ -78,6 +81,7 @@ export const resetPasswordFromTokenHandler = async ({
|
|||
const salt = generateSalt();
|
||||
const hashedPassword = await hashPassword(newpassword, salt);
|
||||
await db
|
||||
.$pickTables<"users">()
|
||||
.updateTable("users")
|
||||
.set({
|
||||
password: hashedPassword,
|
||||
|
|
@ -133,6 +137,7 @@ export const passwordOverrideHandler = async ({
|
|||
const hashedPassword = await hashPassword(password, salt);
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"users">()
|
||||
.updateTable("users")
|
||||
.set({
|
||||
password: hashedPassword,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ import type { Querier } from "~/server/db";
|
|||
|
||||
export const getBanList = async ({ db }: { db: Querier }) => {
|
||||
try {
|
||||
return await db.selectFrom("banlist").selectAll().execute();
|
||||
return await db
|
||||
.$pickTables<"banlist">()
|
||||
.selectFrom("banlist")
|
||||
.selectAll()
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -25,6 +29,7 @@ export const addBan = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"banlist">()
|
||||
.insertInto("banlist")
|
||||
.values({
|
||||
type,
|
||||
|
|
@ -54,6 +59,7 @@ export const updateBan = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"banlist">()
|
||||
.updateTable("banlist")
|
||||
.set({
|
||||
type,
|
||||
|
|
@ -72,7 +78,11 @@ export const updateBan = async ({
|
|||
|
||||
export const removeBan = async ({ db, id }: { db: Querier; id: BanlistId }) => {
|
||||
try {
|
||||
await db.deleteFrom("banlist").where("id", "=", id).executeTakeFirst();
|
||||
await db
|
||||
.$pickTables<"banlist">()
|
||||
.deleteFrom("banlist")
|
||||
.where("id", "=", id)
|
||||
.executeTakeFirst();
|
||||
return true;
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ export const getBanner = async ({
|
|||
}) => {
|
||||
try {
|
||||
let query = db
|
||||
.$pickTables<"banners">()
|
||||
.selectFrom("banners")
|
||||
.selectAll()
|
||||
.where("banners.is_active", "=", true);
|
||||
|
|
@ -30,7 +31,11 @@ export const getBanner = async ({
|
|||
|
||||
export const getAllBanners = async ({ db }: { db: Querier }) => {
|
||||
try {
|
||||
return await db.selectFrom("banners").selectAll().execute();
|
||||
return await db
|
||||
.$pickTables<"banners">()
|
||||
.selectFrom("banners")
|
||||
.selectAll()
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -48,6 +53,7 @@ export const addBanner = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"banners">()
|
||||
.insertInto("banners")
|
||||
.values({
|
||||
...input,
|
||||
|
|
@ -72,6 +78,7 @@ export const updateBanner = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"banners">()
|
||||
.updateTable("banners")
|
||||
.set({
|
||||
...input,
|
||||
|
|
@ -97,6 +104,7 @@ export const deleteBanner = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"banners">()
|
||||
.deleteFrom("banners")
|
||||
.where("banners.idbanner", "=", input.idbanner)
|
||||
.execute();
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ export const getRaw = async ({
|
|||
}) => {
|
||||
try {
|
||||
return db
|
||||
.$pickTables<"chats">()
|
||||
.selectFrom("chats")
|
||||
.selectAll()
|
||||
.where("chats.chatid", "=", chatId)
|
||||
|
|
@ -35,6 +36,7 @@ export const getRaw = async ({
|
|||
export const add = async ({ db, userId }: { db: Querier; userId: UsersId }) => {
|
||||
try {
|
||||
const newChat = await db
|
||||
.$pickTables<"chats">()
|
||||
.insertInto("chats")
|
||||
.values({
|
||||
created_at: new Date(),
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export const storeEmail = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"emails">()
|
||||
.insertInto("emails")
|
||||
.values({
|
||||
data,
|
||||
|
|
@ -32,6 +33,7 @@ export const storeEmail = async ({
|
|||
export const getEmails = async () => {
|
||||
try {
|
||||
const mails = await db
|
||||
.$pickTables<"emails" | "users">()
|
||||
.selectFrom("emails")
|
||||
.innerJoin("users", "users.id", "emails.user_id")
|
||||
.selectAll("emails")
|
||||
|
|
@ -55,6 +57,7 @@ export const getEmails = async () => {
|
|||
|
||||
if (obsoleteMails.length > 0) {
|
||||
await db
|
||||
.$pickTables<"emails">()
|
||||
.deleteFrom("emails")
|
||||
.where(
|
||||
"id_email",
|
||||
|
|
@ -76,6 +79,7 @@ export const getEmails = async () => {
|
|||
export const getUserEmails = async ({ userId }: { userId: UsersId }) => {
|
||||
try {
|
||||
const mails = await db
|
||||
.$pickTables<"emails">()
|
||||
.selectFrom("emails")
|
||||
.selectAll()
|
||||
.where("user_id", "=", userId)
|
||||
|
|
@ -96,6 +100,7 @@ export const getUserEmails = async ({ userId }: { userId: UsersId }) => {
|
|||
|
||||
if (obsoleteMails.length > 0) {
|
||||
await db
|
||||
.$pickTables<"emails">()
|
||||
.deleteFrom("emails")
|
||||
.where(
|
||||
"id_email",
|
||||
|
|
@ -120,7 +125,11 @@ export const deleteEmail = async ({
|
|||
id_email: EmailsIdEmail;
|
||||
}) => {
|
||||
try {
|
||||
await db.deleteFrom("emails").where("id_email", "=", id_email).execute();
|
||||
await db
|
||||
.$pickTables<"emails">()
|
||||
.deleteFrom("emails")
|
||||
.where("id_email", "=", id_email)
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -131,7 +140,11 @@ export const deleteEmail = async ({
|
|||
|
||||
export const deleteAllUserEmails = async ({ userId }: { userId: UsersId }) => {
|
||||
try {
|
||||
await db.deleteFrom("emails").where("user_id", "=", userId).execute();
|
||||
await db
|
||||
.$pickTables<"emails">()
|
||||
.deleteFrom("emails")
|
||||
.where("user_id", "=", userId)
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ export const AddIntrest = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"servizio_interessi">()
|
||||
.insertInto("servizio_interessi")
|
||||
.values({
|
||||
annuncioId,
|
||||
|
|
@ -38,6 +39,7 @@ export const RemoveInterest = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"servizio_interessi">()
|
||||
.deleteFrom("servizio_interessi")
|
||||
.where("annuncioId", "=", annuncioId)
|
||||
.where("userId", "=", userId)
|
||||
|
|
@ -61,6 +63,7 @@ export const HasUserInterest = async ({
|
|||
}) => {
|
||||
try {
|
||||
const interest = await db
|
||||
.$pickTables<"servizio_interessi">()
|
||||
.selectFrom("servizio_interessi")
|
||||
.where("annuncioId", "=", annuncioId)
|
||||
.where("userId", "=", userId)
|
||||
|
|
@ -80,6 +83,7 @@ export const GetUserInterests = async (userId: UsersId) => {
|
|||
try {
|
||||
return (
|
||||
await db
|
||||
.$pickTables<"servizio_interessi">()
|
||||
.selectFrom("servizio_interessi")
|
||||
.where("userId", "=", userId)
|
||||
.select("annuncioId")
|
||||
|
|
@ -99,6 +103,7 @@ export const GetUserInterestsAnnunci = async (userId: UsersId) => {
|
|||
return [];
|
||||
}
|
||||
const annunci = await db
|
||||
.$pickTables<"annunci" | "images_refs" | "videos_refs">()
|
||||
.selectFrom("annunci")
|
||||
.select((_eb) => [
|
||||
"annunci.id",
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ export const getOrdini = async (
|
|||
): Promise<Ordini_w_Utente[]> => {
|
||||
try {
|
||||
let qry = db
|
||||
.$pickTables<"ordini" | "users">()
|
||||
.selectFrom("ordini")
|
||||
.selectAll("ordini")
|
||||
.innerJoin("users", "users.id", "ordini.userid")
|
||||
|
|
@ -47,6 +48,7 @@ export const getOrdini = async (
|
|||
export const getOrdineById = async (ordineId: OrdiniOrdineId) => {
|
||||
try {
|
||||
const data = await db
|
||||
.$pickTables<"ordini" | "users" | "users_anagrafica">()
|
||||
.selectFrom("ordini")
|
||||
.selectAll("ordini")
|
||||
.innerJoin("users", "users.id", "ordini.userid")
|
||||
|
|
@ -89,6 +91,7 @@ export const createOrdine = async (
|
|||
) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"ordini">()
|
||||
.insertInto("ordini")
|
||||
.values(data)
|
||||
.returningAll()
|
||||
|
|
@ -103,7 +106,11 @@ export const createOrdine = async (
|
|||
|
||||
export const removeOrder = async (ordineId: OrdiniOrdineId) => {
|
||||
try {
|
||||
await db.deleteFrom("ordini").where("ordine_id", "=", ordineId).execute();
|
||||
await db
|
||||
.$pickTables<"ordini">()
|
||||
.deleteFrom("ordini")
|
||||
.where("ordine_id", "=", ordineId)
|
||||
.execute();
|
||||
return true;
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
|
|
@ -122,6 +129,7 @@ export const updateOrder = async ({
|
|||
}) => {
|
||||
try {
|
||||
const updated = await db
|
||||
.$pickTables<"ordini">()
|
||||
.updateTable("ordini")
|
||||
.set(data)
|
||||
.where("ordine_id", "=", ordineId)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export const CONDIZIONI_DEFAULT = "CONDIZIONI_CERCHI" as TestiEStringheStingaId;
|
|||
export const getPrezziario = async () => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("isActive", "=", true)
|
||||
|
|
@ -31,6 +32,7 @@ export const getPrezziario = async () => {
|
|||
export const getPrezziarioByIdHandler = async (id: PrezziarioIdprezziario) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("prezziario.idprezziario", "=", id)
|
||||
|
|
@ -52,6 +54,7 @@ export const addPrezziario = async ({
|
|||
}): Promise<Prezziario> => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"prezziario">()
|
||||
.insertInto("prezziario")
|
||||
.values(input)
|
||||
.returningAll()
|
||||
|
|
@ -76,6 +79,7 @@ export const updatePrezziario = async ({
|
|||
}): Promise<Prezziario> => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"prezziario">()
|
||||
.updateTable("prezziario")
|
||||
.set(input)
|
||||
.where("prezziario.idprezziario", "=", prezziarioId)
|
||||
|
|
@ -131,6 +135,7 @@ export const getPrezziarioByTipologia = async ({
|
|||
try {
|
||||
const { acconto, saldi } = await db.transaction().execute(async (trx) => {
|
||||
const acconto = await trx
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.select(["idprezziario", "prezzo_cent", "nome_it", "nome_en", "sconto"])
|
||||
.where("order_type", "=", orderTypeEnum.enum.Acconto)
|
||||
|
|
@ -145,6 +150,7 @@ export const getPrezziarioByTipologia = async ({
|
|||
});
|
||||
}
|
||||
const saldi = await trx
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.select(["idprezziario", "prezzo_cent", "nome_it", "nome_en", "sconto"])
|
||||
.where("order_type", "=", orderTypeEnum.enum.Saldo)
|
||||
|
|
@ -177,6 +183,7 @@ export const getPrezziarioConsulenza = async ({ db }: { db: Querier }) => {
|
|||
try {
|
||||
return await db.transaction().execute(async (trx) => {
|
||||
const prezzi = await trx
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.select(["idprezziario", "prezzo_cent", "nome_it", "nome_en", "sconto"])
|
||||
.where("order_type", "=", orderTypeEnum.enum.Consulenza)
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ export async function setTyping(
|
|||
username: string,
|
||||
): Promise<void> {
|
||||
await db
|
||||
.$pickTables<"typing_status">()
|
||||
.insertInto("typing_status")
|
||||
.values({
|
||||
chatid: chatId,
|
||||
|
|
@ -70,6 +71,7 @@ export async function clearTyping(
|
|||
userId: UsersId,
|
||||
): Promise<void> {
|
||||
await db
|
||||
.$pickTables<"typing_status">()
|
||||
.deleteFrom("typing_status")
|
||||
.where("chatid", "=", chatId)
|
||||
.where("userid", "=", userId)
|
||||
|
|
@ -85,6 +87,7 @@ export async function pruneStaleTyping(
|
|||
): Promise<void> {
|
||||
const cutoff = new Date(Date.now() - maxAgeMs);
|
||||
await db
|
||||
.$pickTables<"typing_status">()
|
||||
.deleteFrom("typing_status")
|
||||
.where("chatid", "=", chatId)
|
||||
.where("last_ping", "<", cutoff)
|
||||
|
|
@ -99,6 +102,7 @@ export async function getTypingList(
|
|||
chatId: ChatsChatid,
|
||||
): Promise<Array<{ userId: UsersId; username: string }>> {
|
||||
const rows = await db
|
||||
.$pickTables<"typing_status">()
|
||||
.selectFrom("typing_status")
|
||||
.select(["userid as userId", "username"])
|
||||
.where("chatid", "=", chatId)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import {
|
|||
export const getRinnoviUser = async (userId: UsersId) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"rinnovi">()
|
||||
.selectFrom("rinnovi")
|
||||
.where("userId", "=", userId)
|
||||
.selectAll()
|
||||
|
|
@ -34,6 +35,7 @@ export type RinnovoData = Awaited<ReturnType<typeof getRinnovoData>>;
|
|||
export const getRinnovoData = async (rinnovoId: RinnoviId) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"rinnovi" | "ordini">()
|
||||
.selectFrom("rinnovi")
|
||||
.where("id", "=", rinnovoId)
|
||||
.selectAll("rinnovi")
|
||||
|
|
@ -59,6 +61,7 @@ export const getRinnovoData = async (rinnovoId: RinnoviId) => {
|
|||
export const createRinnovo = async (data: NewRinnovi) => {
|
||||
try {
|
||||
const rinnovo = await db
|
||||
.$pickTables<"rinnovi">()
|
||||
.insertInto("rinnovi")
|
||||
.values(data)
|
||||
.returningAll()
|
||||
|
|
@ -98,6 +101,7 @@ export const updateRinnovo = async ({
|
|||
try {
|
||||
if (data.decorrenza && data.scadenza) {
|
||||
const rinnovo = await db
|
||||
.$pickTables<"rinnovi">()
|
||||
.selectFrom("rinnovi")
|
||||
.where("id", "=", rinnovoId)
|
||||
.selectAll()
|
||||
|
|
@ -130,6 +134,7 @@ export const updateRinnovo = async ({
|
|||
if (existingPack.pack.idprezziario !== newPack.pack.idprezziario) {
|
||||
//update ordine with new pack and price if permanenza is being updated and ordine is not active yet
|
||||
await db
|
||||
.$pickTables<"ordini">()
|
||||
.updateTable("ordini")
|
||||
.set({
|
||||
amount_cent: newPack.pack.prezzo_cent,
|
||||
|
|
@ -143,6 +148,7 @@ export const updateRinnovo = async ({
|
|||
}
|
||||
|
||||
return await db
|
||||
.$pickTables<"rinnovi">()
|
||||
.updateTable("rinnovi")
|
||||
.set(data)
|
||||
.where("id", "=", rinnovoId)
|
||||
|
|
@ -160,7 +166,11 @@ export const updateRinnovo = async ({
|
|||
|
||||
export const deleteRinnovo = async (rinnovoId: RinnoviId) => {
|
||||
try {
|
||||
await db.deleteFrom("rinnovi").where("id", "=", rinnovoId).execute();
|
||||
await db
|
||||
.$pickTables<"rinnovi">()
|
||||
.deleteFrom("rinnovi")
|
||||
.where("id", "=", rinnovoId)
|
||||
.execute();
|
||||
return true;
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export const addServizio = async (data: NewServizio) => {
|
|||
try {
|
||||
return await db.transaction().execute(async (tx) => {
|
||||
const servizio = await tx
|
||||
.$pickTables<"servizio">()
|
||||
.insertInto("servizio")
|
||||
.values(data)
|
||||
.returningAll()
|
||||
|
|
@ -22,6 +23,7 @@ export const addServizio = async (data: NewServizio) => {
|
|||
);
|
||||
|
||||
const acconto = await db
|
||||
.$pickTables<"prezziario">()
|
||||
.selectFrom("prezziario")
|
||||
.selectAll()
|
||||
.where("isActive", "=", true)
|
||||
|
|
@ -57,6 +59,7 @@ export const addServizio = async (data: NewServizio) => {
|
|||
export const getServizioById = async (servizioId: ServizioServizioId) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"servizio">()
|
||||
.selectFrom("servizio")
|
||||
.selectAll()
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -80,6 +83,7 @@ export const updateServizio = async ({
|
|||
}) => {
|
||||
try {
|
||||
const isDisabledPrev = await db
|
||||
.$pickTables<"servizio">()
|
||||
.selectFrom("servizio")
|
||||
.select("isDisabled")
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -87,6 +91,7 @@ export const updateServizio = async ({
|
|||
() => new Error(`Servizio not found - servizioId: ${servizioId}`),
|
||||
);
|
||||
const updated = await db
|
||||
.$pickTables<"servizio">()
|
||||
.updateTable("servizio")
|
||||
.set(data)
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -111,6 +116,7 @@ export const updateServizio = async ({
|
|||
export const deleteServizio = async (servizioId: ServizioServizioId) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"servizio">()
|
||||
.deleteFrom("servizio")
|
||||
.where("servizio_id", "=", servizioId)
|
||||
.execute();
|
||||
|
|
@ -134,6 +140,7 @@ export const getServizioAnnuncio = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"servizio_annunci">()
|
||||
.selectFrom("servizio_annunci")
|
||||
.selectAll()
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -163,6 +170,7 @@ export const updateServizioAnnuncio = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"servizio_annunci">()
|
||||
.updateTable("servizio_annunci")
|
||||
.set(data)
|
||||
.where("servizio_id", "=", servizioId)
|
||||
|
|
@ -184,6 +192,7 @@ export const deleteServizioAnnuncio = async (
|
|||
) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"servizio_annunci">()
|
||||
.deleteFrom("servizio_annunci")
|
||||
.where("servizio_id", "=", servizioId)
|
||||
.where("annunci_id", "=", annuncioId)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@ import type { Querier } from "~/server/db";
|
|||
|
||||
export const getStringhe = async ({ db }: { db: Querier }) => {
|
||||
try {
|
||||
return await db.selectFrom("testi_e_stringhe").selectAll().execute();
|
||||
return await db
|
||||
.$pickTables<"testi_e_stringhe">()
|
||||
.selectFrom("testi_e_stringhe")
|
||||
.selectAll()
|
||||
.execute();
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
|
|
@ -21,6 +25,7 @@ export const getStringheFiltered = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"testi_e_stringhe">()
|
||||
.selectFrom("testi_e_stringhe")
|
||||
.where("stinga_id", "like", `%${contains}%` as TestiEStringheStingaId)
|
||||
.selectAll()
|
||||
|
|
@ -42,6 +47,7 @@ export const getStringa = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"testi_e_stringhe">()
|
||||
.selectFrom("testi_e_stringhe")
|
||||
.selectAll()
|
||||
.where("stinga_id", "=", stringaId)
|
||||
|
|
@ -65,6 +71,7 @@ export const newStringa = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"testi_e_stringhe">()
|
||||
.insertInto("testi_e_stringhe")
|
||||
.values({ stinga_id: stringaId, stringa_value: stringaValue })
|
||||
.returning("stinga_id")
|
||||
|
|
@ -88,6 +95,7 @@ export const updateStringhe = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"testi_e_stringhe">()
|
||||
.updateTable("testi_e_stringhe")
|
||||
.set({ stringa_value: stringaValue })
|
||||
.where("stinga_id", "=", stringaId)
|
||||
|
|
@ -110,6 +118,7 @@ export const deleteStringa = async ({
|
|||
}) => {
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"testi_e_stringhe">()
|
||||
.deleteFrom("testi_e_stringhe")
|
||||
.where("stinga_id", "=", stringaId)
|
||||
.execute();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { db } from "~/server/db";
|
|||
export async function get(key: string) {
|
||||
try {
|
||||
const row = await db
|
||||
.$pickTables<"tiles_cache">()
|
||||
.selectFrom("tiles_cache")
|
||||
.select(["value", "expires_at"])
|
||||
.where("key", "=", key as TilesCacheKey)
|
||||
|
|
@ -36,6 +37,7 @@ export async function set(
|
|||
|
||||
try {
|
||||
await db
|
||||
.$pickTables<"tiles_cache">()
|
||||
.insertInto("tiles_cache")
|
||||
.values({
|
||||
key: key as TilesCacheKey,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { db, type Querier } from "~/server/db";
|
|||
export const findUser_byId = async ({ id }: { id: string }) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.selectAll()
|
||||
.where("id", "=", id as UsersId)
|
||||
|
|
@ -21,6 +22,7 @@ export const findUser_byId = async ({ id }: { id: string }) => {
|
|||
export const findUser_byEmail = async ({ email }: { email: string }) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.selectAll()
|
||||
.where("email", "=", email)
|
||||
|
|
@ -39,6 +41,7 @@ export const findUser_byId_MINI = async ({
|
|||
}): Promise<Session | undefined> => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.select([
|
||||
"id",
|
||||
|
|
@ -68,6 +71,7 @@ export const getUser = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"users">()
|
||||
.selectFrom("users")
|
||||
.selectAll()
|
||||
.where("id", "=", userId)
|
||||
|
|
@ -91,6 +95,7 @@ export const addUser = async ({
|
|||
}) => {
|
||||
try {
|
||||
const user = await db
|
||||
.$pickTables<"users">()
|
||||
.insertInto("users")
|
||||
.values({
|
||||
...data,
|
||||
|
|
@ -118,6 +123,7 @@ export const getClientProfilo = async ({
|
|||
}) => {
|
||||
try {
|
||||
return await db
|
||||
.$pickTables<"users" | "users_anagrafica" | "users_storage">()
|
||||
.selectFrom("users")
|
||||
.select([
|
||||
"id",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue