72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
|
"use server";
|
||
|
|
||
|
import {Configuration, DefaultApi} from "../../../proto/tester/v1/api";
|
||
|
import {cookies} from "next/headers";
|
||
|
import {AxiosRequestConfig} from "axios";
|
||
|
|
||
|
const configuration = new Configuration({
|
||
|
basePath: "http://localhost:60060",
|
||
|
});
|
||
|
|
||
|
const testerApi = new DefaultApi(configuration);
|
||
|
|
||
|
const CookieName: any = "SESSIONID";
|
||
|
|
||
|
export const ListContests = async (page: number, pageSize: number) => {
|
||
|
const cookieStore = await cookies();
|
||
|
|
||
|
const session = cookieStore.get(CookieName);
|
||
|
|
||
|
if (session === undefined) {
|
||
|
throw new Error("Session id not found");
|
||
|
}
|
||
|
|
||
|
const options: AxiosRequestConfig = {
|
||
|
headers: {
|
||
|
'Authorization': "Bearer " + session.value
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const response = await testerApi.listContests(page, pageSize, options);
|
||
|
|
||
|
return response.data;
|
||
|
};
|
||
|
|
||
|
export const GetContest = async (id: number) => {
|
||
|
const cookieStore = await cookies();
|
||
|
|
||
|
const session = cookieStore.get(CookieName);
|
||
|
|
||
|
if (session === undefined) {
|
||
|
throw new Error("Session id not found");
|
||
|
}
|
||
|
|
||
|
const options: AxiosRequestConfig = {
|
||
|
headers: {
|
||
|
'Authorization': "Bearer " + session.value
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const response = await testerApi.getContest(id, options);
|
||
|
|
||
|
return response.data;
|
||
|
};
|
||
|
|
||
|
export const DeleteTask = async (taskId: number) => {
|
||
|
const cookieStore = await cookies();
|
||
|
|
||
|
const session = cookieStore.get(CookieName);
|
||
|
|
||
|
if (session === undefined) {
|
||
|
throw new Error("Session id not found");
|
||
|
}
|
||
|
|
||
|
const options: AxiosRequestConfig = {
|
||
|
headers: {
|
||
|
'Authorization': "Bearer " + session.value
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const response = await testerApi.deleteTask(taskId, options);
|
||
|
return response.data;
|
||
|
}
|