Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phoenixlan/phoenix.js",
"version": "3.5.5",
"version": "4.0.0",
"description": "Phoenix LAN api javascript wrapper",
"main": "build/index.js",
"module": "build/index.es.js",
Expand Down
7 changes: 3 additions & 4 deletions src/agenda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface AgendaEntry {
description: string;
}

export const getAgenda = async (): Promise<Array<AgendaEntry[]>> => {
const response = await fetch(`${getApiServer()}/agenda/`, {
export const getAgenda = async (event_uuid: string): Promise<Array<AgendaEntry[]>> => {
const response = await fetch(`${getApiServer()}/event/${event_uuid}/agenda`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -48,14 +48,13 @@ export const createAgendaEntry = async (
duration: number,
pinned: boolean
) => {
const response = await fetch(`${getApiServer()}/agenda`, {
const response = await fetch(`${getApiServer()}/event/${event_uuid}/agenda`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
...(await Oauth.getAuthHeaders())
},
body: JSON.stringify({
event_uuid,
title,
description,
location,
Expand Down
132 changes: 132 additions & 0 deletions src/cardOrder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import {getApiServer} from "../meta";
import * as Oauth from "../user/oauth";
import {ApiDeleteError, ApiGetError, ApiPatchError, ApiPostError} from "../errors";
import { BasicUser } from "../user";

export type CardOrderState = 'CREATED' | 'IN_PROGRESS' | 'FINISHED' | 'CANCELLED';

export interface CardOrder {
uuid: string;
event_uuid: string;
subject_user: BasicUser;
creator_user: BasicUser;
updated_by_user: BasicUser | null;
last_updated: number;
created: number;
state: CardOrderState;
}

export const createCardOrder = async (event_uuid: string, user_uuid: string): Promise<CardOrder> => {
const response = await fetch(`${getApiServer()}/event/${event_uuid}/card_order`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(await Oauth.getAuthHeaders()),
},
body: JSON.stringify({
user_uuid
})
});

if (!response.ok) {
let error = ""
try {
error = (await response.json())['error']
} catch (e) {
throw new ApiPostError('Unable to create card order');
}

throw new ApiPostError(error);
}

return (await response.json()) as CardOrder;
}

export const getEventCardOrders = async (event_uuid: string): Promise<Array<CardOrder>> => {
const response = await fetch(`${getApiServer()}/event/${event_uuid}/card_orders`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
...(await Oauth.getAuthHeaders()),
},
});

if (!response.ok) {
throw new ApiGetError('Unable to get card orders');
}

return (await response.json()) as Array<CardOrder>;
}

export const getCardOrder = async (uuid: string): Promise<CardOrder> => {
const response = await fetch(`${getApiServer()}/card_order/${uuid}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
...(await Oauth.getAuthHeaders()),
},
});

if (!response.ok) {
throw new ApiGetError('Unable to get card order');
}

return (await response.json()) as CardOrder;
}

export const generateCardOrder = async (uuid: string) => {
const response = await fetch(`${getApiServer()}/card_order/${uuid}/generate`, {
method: 'PATCH',
headers: {
...(await Oauth.getAuthHeaders()),
},
});

return response;
}

export const finishCardOrder = async (uuid: string): Promise<CardOrder> => {
const response = await fetch(`${getApiServer()}/card_order/${uuid}/finish`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
...(await Oauth.getAuthHeaders()),
},
});

if (!response.ok) {
let error = ""
try {
error = (await response.json())['error']
} catch (e) {
throw new ApiPatchError('Unable to finish card order');
}

throw new ApiPatchError(error);
}

return (await response.json()) as CardOrder;
}

export const cancelCardOrder = async (uuid: string): Promise<CardOrder> => {
const response = await fetch(`${getApiServer()}/card_order/${uuid}/cancel`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
...(await Oauth.getAuthHeaders()),
},
});

if (!response.ok) {
let error = ""
try {
error = (await response.json())['error']
} catch (e) {
throw new ApiDeleteError('Unable to cancel card order');
}

throw new ApiDeleteError(error);
}

return (await response.json()) as CardOrder;
}
26 changes: 2 additions & 24 deletions src/crew/applications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,6 @@ export const getApplication = async (uuid: string): Promise<BasicApplication> =>
return (await response.json()) as BasicApplication;
};

// Scream test
/*
export const getAllApplicationsByEvent = async (event: Event): Promise<Array<BasicApplication>> => {
if (!event) {
throw new ApiParameterError('Event cannot be null');
}
const response = await fetch(`${getApiServer()}/event/${event.uuid}/applications`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
...(await Oauth.getAuthHeaders()),
},
});

if (response.status !== 200) {
throw new ApiGetError('Unable to get applications');
}

return (await response.json()) as Array<BasicApplication>;
};
*/

export const getUserApplications = async (): Promise<Array<BasicApplication>> => {
const response = await fetch(`${getApiServer()}/application/my`, {
method: 'GET',
Expand All @@ -112,8 +90,8 @@ export const getUserApplications = async (): Promise<Array<BasicApplication>> =>
return (await response.json()) as Array<BasicApplication>;
};

export const createApplication = async (crews: Array<string>, contents: string): Promise<BasicApplication> => {
const response = await fetch(`${getApiServer()}/application`, {
export const createApplication = async (event_uuid: string, crews: Array<string>, contents: string): Promise<BasicApplication> => {
const response = await fetch(`${getApiServer()}/event/${event_uuid}/application`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down
6 changes: 4 additions & 2 deletions src/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { getApiServer } from "../meta";
import { BasicUser, Oauth } from "../user";
import { ApiGetError, ApiPostError, ApiPutError } from "../errors";

export const emailDryrun = async (recipient_category: string, subject: string, body: string, argument?: string) => {
export const emailDryrun = async (brand_uuid: string, recipient_category: string, subject: string, body: string, argument?: string) => {
const response = await fetch(`${getApiServer()}/email/dryrun`, {
method: 'POST',
headers: {
"Content-Type": "application/json",
...(await Oauth.getAuthHeaders()),
}, body: JSON.stringify({
brand_uuid,
recipient_category,
subject,
body,
Expand All @@ -28,13 +29,14 @@ export const emailDryrun = async (recipient_category: string, subject: string, b
return await response.json()
}

export const sendEmails = async (recipient_category: string, subject: string, body: string, argument?: string) => {
export const sendEmails = async (brand_uuid: string, recipient_category: string, subject: string, body: string, argument?: string) => {
const response = await fetch(`${getApiServer()}/email/send`, {
method: 'POST',
headers: {
"Content-Type": "application/json",
...(await Oauth.getAuthHeaders()),
}, body: JSON.stringify({
brand_uuid,
recipient_category,
subject,
body,
Expand Down
64 changes: 64 additions & 0 deletions src/eventBrand/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {getApiServer} from "../meta";
import * as Oauth from "../user/oauth";
import {ApiGetError, ApiPostError} from "../errors";

export interface EventBrand {
uuid: string;
name: string;
}

export const getEventBrands = async (): Promise<Array<EventBrand>> => {
const response = await fetch(`${getApiServer()}/event_brand`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new ApiGetError('Unable to get event brands');
}

return (await response.json()) as Array<EventBrand>;
}

export const getEventBrand = async (uuid: string): Promise<EventBrand> => {
const response = await fetch(`${getApiServer()}/event_brand/${uuid}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new ApiGetError('Unable to get the event brand');
}

return (await response.json()) as EventBrand;
}

export const createEventBrand = async (name: string): Promise<EventBrand> => {
const response = await fetch(`${getApiServer()}/event_brand`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(await Oauth.getAuthHeaders()),
},
body: JSON.stringify({
name
})
});

if (!response.ok) {
let error = ""
try {
error = (await response.json())['error']
} catch (e) {
throw new ApiPostError('Unable to create event brand');
}

throw new ApiPostError(error);
}

return (await response.json()) as EventBrand;
}
Loading
Loading