refactor: add authorization

This commit is contained in:
Mauricio Siu
2024-10-06 01:37:39 -06:00
parent 7cfbea3f60
commit 3cf27a068a
10 changed files with 191 additions and 33 deletions

View File

@@ -9,12 +9,13 @@ type QueueJob =
cronSchedule: string;
serverId: string;
};
export const schedule = async (job: QueueJob) => {
export const schedule = async (job: QueueJob, authSession: string) => {
try {
const result = await fetch(`${process.env.JOBS_URL}/create-backup`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authSession}`,
},
body: JSON.stringify(job),
});
@@ -27,12 +28,32 @@ export const schedule = async (job: QueueJob) => {
}
};
export const removeJob = async (job: QueueJob) => {
export const removeJob = async (job: QueueJob, authSession: string) => {
try {
const result = await fetch(`${process.env.JOBS_URL}/remove-job`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authSession}`,
},
body: JSON.stringify(job),
});
const data = await result.json();
console.log(data);
return data;
} catch (error) {
console.log(error);
throw error;
}
};
export const updateJob = async (job: QueueJob, authSession: string) => {
try {
const result = await fetch(`${process.env.JOBS_URL}/update-backup`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authSession}`,
},
body: JSON.stringify(job),
});

View File

@@ -1,11 +1,12 @@
import type { DeploymentJob } from "../queues/deployments-queue";
export const deploy = async (jobData: DeploymentJob) => {
export const deploy = async (jobData: DeploymentJob, sessionId: string) => {
try {
const result = await fetch(`${process.env.SERVER_URL}/deploy`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${sessionId}`,
},
body: JSON.stringify(jobData),
});