Updates
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import getQueue from "./get-queue";
|
||||
import {
|
||||
DSQL_DATASQUIREL_PROCESS_QUEUE,
|
||||
DsqlTables,
|
||||
} from "../../../types/dsql";
|
||||
import dsqlCrud from "../../../utils/data-fetching/crud";
|
||||
import numberfy from "../../../utils/numberfy";
|
||||
|
||||
type Param = {
|
||||
queue: DSQL_DATASQUIREL_PROCESS_QUEUE;
|
||||
userId: string | number;
|
||||
dummy?: boolean;
|
||||
};
|
||||
|
||||
export default async function addQueue({ queue, userId, dummy }: Param) {
|
||||
const tableName: (typeof DsqlTables)[number] = "process_queue";
|
||||
|
||||
const existingQueueRes = dummy
|
||||
? undefined
|
||||
: ((await getQueue({
|
||||
query: {
|
||||
query: {
|
||||
user_id: {
|
||||
value: String(userId),
|
||||
},
|
||||
job_type: {
|
||||
value: String(queue.job_type),
|
||||
},
|
||||
},
|
||||
},
|
||||
})) as DSQL_DATASQUIREL_PROCESS_QUEUE[] | undefined);
|
||||
|
||||
const existingQueue = existingQueueRes?.[0];
|
||||
|
||||
if (existingQueue?.id && !dummy) return undefined;
|
||||
|
||||
const addQueueRes = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
|
||||
action: "insert",
|
||||
table: tableName,
|
||||
data: { ...queue, user_id: numberfy(userId) },
|
||||
});
|
||||
|
||||
return addQueueRes;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import dsqlCrud from "../../../utils/data-fetching/crud";
|
||||
import getQueue from "./get-queue";
|
||||
import {
|
||||
DSQL_DATASQUIREL_PROCESS_QUEUE,
|
||||
DsqlTables,
|
||||
} from "../../../types/dsql";
|
||||
|
||||
type Param = {
|
||||
queueId: string | number;
|
||||
userId: string | number;
|
||||
};
|
||||
|
||||
export default async function deleteQueue({ queueId, userId }: Param) {
|
||||
const tableName: (typeof DsqlTables)[number] = "process_queue";
|
||||
|
||||
const existingQueue = (await getQueue({ userId, queueId })) as
|
||||
| DSQL_DATASQUIREL_PROCESS_QUEUE
|
||||
| undefined;
|
||||
|
||||
if (!existingQueue?.id) return false;
|
||||
|
||||
const deleteQueueRes = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
|
||||
action: "delete",
|
||||
table: tableName,
|
||||
targetId: existingQueue.id,
|
||||
});
|
||||
|
||||
return Boolean(deleteQueueRes?.success);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import {
|
||||
DSQL_DATASQUIREL_PROCESS_QUEUE,
|
||||
DsqlTables,
|
||||
} from "../../../types/dsql";
|
||||
import dsqlCrud from "../../../utils/data-fetching/crud";
|
||||
import { DsqlCrudQueryObject, ServerQueryQueryObject } from "../../../types";
|
||||
|
||||
type Param = {
|
||||
queueId?: string | number;
|
||||
userId?: string | number;
|
||||
query?: DsqlCrudQueryObject<DSQL_DATASQUIREL_PROCESS_QUEUE>;
|
||||
single?: boolean;
|
||||
};
|
||||
|
||||
export default async function getQueue({
|
||||
queueId,
|
||||
userId,
|
||||
query,
|
||||
single,
|
||||
}: Param) {
|
||||
const tableName: (typeof DsqlTables)[number] = "process_queue";
|
||||
|
||||
let queryQuery: ServerQueryQueryObject<DSQL_DATASQUIREL_PROCESS_QUEUE> = {};
|
||||
|
||||
if (queueId) {
|
||||
queryQuery = { ...queryQuery, ...{ id: { value: String(queueId) } } };
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
queryQuery = {
|
||||
...queryQuery,
|
||||
...{ user_id: { value: String(userId) } },
|
||||
};
|
||||
}
|
||||
|
||||
const getQueue = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
|
||||
action: "get",
|
||||
table: tableName,
|
||||
query: {
|
||||
...query,
|
||||
query: {
|
||||
...query?.query,
|
||||
...queryQuery,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const queuePayload = getQueue?.payload as
|
||||
| DSQL_DATASQUIREL_PROCESS_QUEUE[]
|
||||
| undefined;
|
||||
|
||||
return queueId || single ? queuePayload?.[0] : queuePayload;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import dsqlCrud from "../../../utils/data-fetching/crud";
|
||||
import {
|
||||
DSQL_DATASQUIREL_PROCESS_QUEUE,
|
||||
DsqlTables,
|
||||
} from "../../../types/dsql";
|
||||
|
||||
type Param = {
|
||||
queueId: string | number;
|
||||
queue: DSQL_DATASQUIREL_PROCESS_QUEUE;
|
||||
};
|
||||
|
||||
export default async function updateQueue({ queueId, queue }: Param) {
|
||||
const tableName: (typeof DsqlTables)[number] = "process_queue";
|
||||
|
||||
const updateQueueRes = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
|
||||
action: "update",
|
||||
table: tableName,
|
||||
targetId: queueId,
|
||||
data: queue,
|
||||
});
|
||||
|
||||
return Boolean(updateQueueRes?.success);
|
||||
}
|
||||
Reference in New Issue
Block a user