|
|
@ -9,7 +9,7 @@ export class ModifyContestService {
|
|
|
|
|
|
|
|
|
|
|
|
async getImages(email: string): Promise<any> {
|
|
|
|
async getImages(email: string): Promise<any> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const response = await fetch('api/getImages', {
|
|
|
|
const response = await fetch('api/images/getImages', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
'Content-Type': 'application/json'
|
|
|
@ -71,7 +71,7 @@ export class ModifyContestService {
|
|
|
|
|
|
|
|
|
|
|
|
async addContest(data: any): Promise<any> {
|
|
|
|
async addContest(data: any): Promise<any> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const response = await fetch('api/AddContest', {
|
|
|
|
const response = await fetch('api/constests/AddContest', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
'Content-Type': 'application/json'
|
|
|
@ -93,7 +93,7 @@ export class ModifyContestService {
|
|
|
|
// Send a POST request to delete the contest by its name
|
|
|
|
// Send a POST request to delete the contest by its name
|
|
|
|
let data = {contest: contestId};
|
|
|
|
let data = {contest: contestId};
|
|
|
|
await this.deleteFlagsFromContest(contestId);
|
|
|
|
await this.deleteFlagsFromContest(contestId);
|
|
|
|
let res = await fetch('api/DeleteContest', {
|
|
|
|
let res = await fetch('api/contests/DeleteContest', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
@ -111,7 +111,7 @@ export class ModifyContestService {
|
|
|
|
|
|
|
|
|
|
|
|
async deleteFlagsFromContest(contestId: number): Promise<any> {
|
|
|
|
async deleteFlagsFromContest(contestId: number): Promise<any> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const response = await fetch('api/DeleteFlagsFromContest', {
|
|
|
|
const response = await fetch('api/flags/DeleteFlagsFromContest', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
'Content-Type': 'application/json'
|
|
|
@ -131,7 +131,7 @@ export class ModifyContestService {
|
|
|
|
|
|
|
|
|
|
|
|
async AddFlag(data: any): Promise<any> {
|
|
|
|
async AddFlag(data: any): Promise<any> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const response = await fetch('api/AddFlag', {
|
|
|
|
const response = await fetch('api/flags/AddFlag', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
'Content-Type': 'application/json'
|
|
|
@ -151,7 +151,7 @@ export class ModifyContestService {
|
|
|
|
|
|
|
|
|
|
|
|
async DeleteFlag(flagId: number): Promise<any> {
|
|
|
|
async DeleteFlag(flagId: number): Promise<any> {
|
|
|
|
let data = { flag: flagId };
|
|
|
|
let data = { flag: flagId };
|
|
|
|
let res = await fetch('api/DeleteFlag', {
|
|
|
|
let res = await fetch('api/flags/DeleteFlag', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
@ -164,7 +164,7 @@ export class ModifyContestService {
|
|
|
|
const image = flagImage;
|
|
|
|
const image = flagImage;
|
|
|
|
// set up the container for the image
|
|
|
|
// set up the container for the image
|
|
|
|
const data = { FlagImage: image, email: Email };
|
|
|
|
const data = { FlagImage: image, email: Email };
|
|
|
|
const res = await fetch('/api/setNewActiveFlag', {
|
|
|
|
const res = await fetch('/api/flags/setNewActiveFlag', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Content-Type' : 'application/json'
|
|
|
|
'Content-Type' : 'application/json'
|
|
|
@ -174,28 +174,50 @@ export class ModifyContestService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async setContestActive(contestId: number, email: string): Promise<any> {
|
|
|
|
async setContestActive(contestId: number, email: string): Promise<any> {
|
|
|
|
try {
|
|
|
|
const oldcontestID = await this.getActiveContest(email);
|
|
|
|
const response = await fetch('api/setContestActive', {
|
|
|
|
if(oldcontestID !== 0 && oldcontestID === contestId){
|
|
|
|
method: 'POST',
|
|
|
|
try{
|
|
|
|
headers: {
|
|
|
|
const response = await fetch('api/contests/EndContest', {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
method: 'POST',
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
body: JSON.stringify({ contest: contestId, email })
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
body: JSON.stringify({contest: oldcontestID, email})
|
|
|
|
if (!response.ok) {
|
|
|
|
});
|
|
|
|
throw new Error('Failed to set contest active');
|
|
|
|
if(!response.ok)
|
|
|
|
}
|
|
|
|
throw new Error('Failed to end contest');
|
|
|
|
return await response.json();
|
|
|
|
await response.json();
|
|
|
|
} catch (error) {
|
|
|
|
return 0;
|
|
|
|
console.error('Error setting contest active:', error);
|
|
|
|
}catch(error){
|
|
|
|
|
|
|
|
console.error('Error ending contest');
|
|
|
|
throw error;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const response = await fetch('api/contests/setContestActive', {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
body: JSON.stringify({ contest: contestId, email })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
|
|
throw new Error('Failed to set contest active');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await response.json();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error('Error setting contest active:', error);
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async deleteImage(imageName: string): Promise<any> {
|
|
|
|
async deleteImage(imageName: string): Promise<any> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const response = await fetch('api/DeleteImageReplaceFlags', {
|
|
|
|
const response = await fetch('api/images/DeleteImageReplaceFlags', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|