Skip to content

Commit

Permalink
Removed getAll tasks SQL version
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-elhaddad committed Nov 7, 2023
1 parent 96d3836 commit 1ced818
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions src/models/tasks.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Task from '../types/Task.type';
import getDates from '../helpers/getDates';
import prisma from '../lib/database';
import Subtask from '../types/Subtask.type';

class Tasks {
/** Creates a new task assigned to the passed user id.
Expand Down Expand Up @@ -69,45 +68,6 @@ class Tasks {
return tasks;
}

static async getAll_SQLVersion(u_id: number): Promise<Task[]> {
const mp = new Map<Partial<Task>, Partial<Subtask>[]>();
type joinResult = Task & Subtask & { [key: string]: any }; // eslint-disable-line @typescript-eslint/no-explicit-any
const tasks: joinResult[] = await prisma.$queryRaw`
SELECT *
FROM public."Task"
LEFT JOIN public."Subtask"
ON public."Task".t_id = public."Subtask"."s_task_id"
WHERE public."Task"."t_user_id" = ${u_id};
`;

tasks.forEach((el: joinResult) => {
const task: Partial<Task> = {},
subtask: Partial<Subtask> = {};
for (const key in el) {
if (key.startsWith('s_')) subtask[key] = el[key];
else task[key] = el[key];
}
let found = false;
mp.forEach((v, k) => {
if (k.t_id === task.t_id) {
found = true;
return;
}
});
if (!found) mp.set(task, []);

mp.get(task)?.push(subtask);
});
console.log(mp);
const returnTasks: any = []; // eslint-disable-line @typescript-eslint/no-explicit-any
mp.forEach((v, k) => {
const el = k;
el.t_subtasks = v;
returnTasks.push(el);
});
return returnTasks;
}

/** Gets all the tasks assigned to the passed user id and has due date today. */
static async getDueToday(u_id: number, options?: {
t_status?: boolean,
Expand Down

0 comments on commit 1ced818

Please sign in to comment.