From f0758e0645729fb59b3fce17fda2f9c0aafe9e2a Mon Sep 17 00:00:00 2001 From: "Liam S. Crouch" Date: Wed, 2 Sep 2026 00:24:01 +0900 Subject: [PATCH] Multitenancy --- package.json | 2 +- src/agenda/index.ts | 7 +- src/cardOrder/index.ts | 132 ++++++++++++++++++++++++++++++ src/crew/applications/index.ts | 26 +----- src/email/index.ts | 6 +- src/eventBrand/index.ts | 64 +++++++++++++++ src/events/index.ts | 111 +++++++++++++++++++++---- src/index.ts | 3 + src/payment/storeSession/index.ts | 5 +- src/position/index.ts | 8 +- src/position_mapping/index.ts | 4 +- src/roles/index.ts | 62 ++++++++++++++ src/seatmap/index.ts | 26 +++++- src/ticket/index.ts | 24 +----- src/ticketType/index.ts | 36 +++++++- src/user/index.ts | 30 +------ 16 files changed, 435 insertions(+), 111 deletions(-) create mode 100644 src/cardOrder/index.ts create mode 100644 src/eventBrand/index.ts create mode 100644 src/roles/index.ts diff --git a/package.json b/package.json index b987ae4..f2c1e95 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/agenda/index.ts b/src/agenda/index.ts index 412b640..68f56f6 100644 --- a/src/agenda/index.ts +++ b/src/agenda/index.ts @@ -9,8 +9,8 @@ interface AgendaEntry { description: string; } -export const getAgenda = async (): Promise> => { - const response = await fetch(`${getApiServer()}/agenda/`, { +export const getAgenda = async (event_uuid: string): Promise> => { + const response = await fetch(`${getApiServer()}/event/${event_uuid}/agenda`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -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, diff --git a/src/cardOrder/index.ts b/src/cardOrder/index.ts new file mode 100644 index 0000000..b0beee3 --- /dev/null +++ b/src/cardOrder/index.ts @@ -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 => { + 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> => { + 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; +} + +export const getCardOrder = async (uuid: string): Promise => { + 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 => { + 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 => { + 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; +} diff --git a/src/crew/applications/index.ts b/src/crew/applications/index.ts index f30310b..6fbaa0b 100644 --- a/src/crew/applications/index.ts +++ b/src/crew/applications/index.ts @@ -74,28 +74,6 @@ export const getApplication = async (uuid: string): Promise => return (await response.json()) as BasicApplication; }; -// Scream test -/* -export const getAllApplicationsByEvent = async (event: Event): Promise> => { - 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; -}; -*/ - export const getUserApplications = async (): Promise> => { const response = await fetch(`${getApiServer()}/application/my`, { method: 'GET', @@ -112,8 +90,8 @@ export const getUserApplications = async (): Promise> => return (await response.json()) as Array; }; -export const createApplication = async (crews: Array, contents: string): Promise => { - const response = await fetch(`${getApiServer()}/application`, { +export const createApplication = async (event_uuid: string, crews: Array, contents: string): Promise => { + const response = await fetch(`${getApiServer()}/event/${event_uuid}/application`, { method: 'PUT', headers: { 'Content-Type': 'application/json', diff --git a/src/email/index.ts b/src/email/index.ts index 845b12e..c98d588 100644 --- a/src/email/index.ts +++ b/src/email/index.ts @@ -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, @@ -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, diff --git a/src/eventBrand/index.ts b/src/eventBrand/index.ts new file mode 100644 index 0000000..0ae28fc --- /dev/null +++ b/src/eventBrand/index.ts @@ -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> => { + 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; +} + +export const getEventBrand = async (uuid: string): Promise => { + 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 => { + 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; +} diff --git a/src/events/index.ts b/src/events/index.ts index 00c4981..9740e82 100644 --- a/src/events/index.ts +++ b/src/events/index.ts @@ -1,5 +1,5 @@ import {getApiServer} from "../meta"; -import {ApiGetError} from "../errors"; +import {ApiGetError, ApiPatchError, ApiPutError} from "../errors"; import { BasicUserWithSecretFields, Oauth } from "../user"; import { BasicTicket } from "../ticket"; import { TicketType } from "../ticketType"; @@ -7,6 +7,7 @@ import { BasicApplication } from "../crew/applications"; export interface Event { name: string; + event_brand_uuid: string; participant_age_limit_inclusive: number; crew_age_limit_inclusive: number; booking_time: number; @@ -25,10 +26,40 @@ export interface TicketAvailability { total: number; } +export interface NewEvent { + name: string; + start_time: number; + end_time: number; + booking_time: number; + priority_seating_time_delta: number; + seating_time_delta: number; + max_participants: number; + participant_age_limit_inclusive?: number; + crew_age_limit_inclusive?: number; + theme?: string; + location_uuid?: string; + seatmap_uuid?: string; +} -export const getCurrentEvent = async (): Promise => { - const response = await fetch(`${getApiServer()}/event/current`, { +export interface EventChanges { + name?: string; + start_time?: number; + end_time?: number; + booking_time?: number; + priority_seating_time_delta?: number; + seating_time_delta?: number; + max_participants?: number; + participant_age_limit_inclusive?: number; + crew_age_limit_inclusive?: number; + theme?: string | null; + cancellation_reason?: string | null; + seatmap_uuid?: string | null; +} + + +export const getCurrentEvent = async (event_brand_uuid: string): Promise => { + const response = await fetch(`${getApiServer()}/event_brand/${event_brand_uuid}/current_event`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -39,6 +70,54 @@ export const getCurrentEvent = async (): Promise => { throw new ApiGetError('Unable to get the current event'); } + return (await response.json()) as Event | null; +}; + +export const createEvent = async (event_brand_uuid: string, event: NewEvent): Promise => { + const response = await fetch(`${getApiServer()}/event_brand/${event_brand_uuid}/event`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + ...(await Oauth.getAuthHeaders()), + }, + body: JSON.stringify(event) + }); + + if (!response.ok) { + let error = "" + try { + error = (await response.json())['error'] + } catch (e) { + throw new ApiPutError('Unable to create event'); + } + + throw new ApiPutError(error); + } + + return (await response.json()) as Event; +}; + +export const updateEvent = async (uuid: string, changes: EventChanges): Promise => { + const response = await fetch(`${getApiServer()}/event/${uuid}`, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + ...(await Oauth.getAuthHeaders()), + }, + body: JSON.stringify(changes) + }); + + if (!response.ok) { + let error = "" + try { + error = (await response.json())['error'] + } catch (e) { + throw new ApiPatchError('Unable to update event'); + } + + throw new ApiPatchError(error); + } + return (await response.json()) as Event; }; @@ -106,21 +185,6 @@ export const addEventTicketType = async (event_uuid: string, ticket_type_uuid: s return (await response.json()) as Array; }; -export const getEventMembersRequiringMembership = async (uuid: string): Promise> => { - const response = await fetch(`${getApiServer()}/event/${uuid}/customers_requiring_memberships`, { - method: 'GET', - headers: { - ...(await Oauth.getAuthHeaders()), - } - }); - - if (response.status !== 200) { - throw new ApiGetError("Unable to get customers requiring memberships"); - } - - return (await response.json()) as Array; -}; - export const getEventNewMembers = async (uuid: string): Promise> => { const response = await fetch(`${getApiServer()}/event/${uuid}/new_memberships`, { method: 'GET', @@ -166,6 +230,17 @@ export const getEventTicketAvailability = async (uuid: string): Promise { + const response = await fetch(`${getApiServer()}/event/${event_uuid}/crew_card?user_uuid=${encodeURIComponent(user_uuid)}`, { + method: 'GET', + headers: { + ...(await Oauth.getAuthHeaders()), + } + }); + + return response; +}; + export const getApplicationsByEvent = async (event_uuid: string): Promise> => { const response = await fetch(`${getApiServer()}/event/${event_uuid}/applications`, { method: 'GET', diff --git a/src/index.ts b/src/index.ts index a7eb3f9..c62f8dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ export * as User from './user'; export * from './meta'; export * from './events'; +export * as EventBrand from './eventBrand'; export * as Crew from './crew'; export * from './errors'; export * as Avatar from './avatar'; @@ -18,5 +19,7 @@ export * from './payment'; export * as Agenda from './agenda'; export * as Email from "./email"; export * as Friendship from './friend_request'; +export * as CardOrder from './cardOrder'; +export * as Roles from './roles'; export const PHOENIX_FLAG = "PHOENIX{n07h1n6_0n_617hub}" \ No newline at end of file diff --git a/src/payment/storeSession/index.ts b/src/payment/storeSession/index.ts index 9228b9a..2b36484 100644 --- a/src/payment/storeSession/index.ts +++ b/src/payment/storeSession/index.ts @@ -28,6 +28,7 @@ export interface StoreSession { expires: number, total: number, user_uuid: string, + event_uuid: string, uuid: string, } @@ -46,8 +47,8 @@ export const getActiveStoreSessions = async () => { return (await response.json()) as Array; } -export const createStoreSession = async (data: Cart) => { - const response = await fetch(`${getApiServer()}/store_session`, { +export const createStoreSession = async (event_uuid: string, data: Cart) => { + const response = await fetch(`${getApiServer()}/event/${event_uuid}/store_session`, { method: 'PUT', headers: { 'Content-Type': 'application/json', diff --git a/src/position/index.ts b/src/position/index.ts index 9aa877a..afe5e7d 100644 --- a/src/position/index.ts +++ b/src/position/index.ts @@ -20,6 +20,7 @@ export interface Permission { } export type BasicPosition = { + event_brand_uuid: string, position_mappings: Array, } & BasePosition @@ -57,7 +58,7 @@ export const getPositions = async () => { return (await response.json()) as Array; } -export const createPosition = async (name: string, description: string, chief: boolean, is_vanity: boolean, crew_uuid?: string, team_uuid?: string) => { +export const createPosition = async (name: string, description: string, chief: boolean, is_vanity: boolean, crew_uuid?: string, team_uuid?: string, event_brand_uuid?: string) => { const response = await fetch(`${getApiServer()}/position/`, { method: 'POST', headers: { @@ -69,7 +70,8 @@ export const createPosition = async (name: string, description: string, chief: b chief, is_vanity, crew_uuid, - team_uuid + team_uuid, + ...(event_brand_uuid ? { event_brand_uuid } : {}) }) }); @@ -86,5 +88,5 @@ export const createPosition = async (name: string, description: string, chief: b throw new ApiPostError(error); } - return (await response.json()) as FullPosition; + return (await response.json()) as BasicPosition; } \ No newline at end of file diff --git a/src/position_mapping/index.ts b/src/position_mapping/index.ts index ae7d831..b36bef7 100644 --- a/src/position_mapping/index.ts +++ b/src/position_mapping/index.ts @@ -48,8 +48,8 @@ export const deletePositionMapping = async (position_mapping_uuid: string) => { return true; } -export const createPositionMapping = async (user_uuid: string, position_uuid: string) => { - const response = await fetch(`${getApiServer()}/position_mapping/`, { +export const createPositionMapping = async (event_uuid: string, user_uuid: string, position_uuid: string) => { + const response = await fetch(`${getApiServer()}/event/${event_uuid}/position_mapping`, { method: 'POST', headers: { ...(await Oauth.getAuthHeaders()), diff --git a/src/roles/index.ts b/src/roles/index.ts new file mode 100644 index 0000000..34f49ef --- /dev/null +++ b/src/roles/index.ts @@ -0,0 +1,62 @@ +import { JWTPayload } from "../user/oauth"; + +export type Permission = string; + +export const ADMIN: Permission = "admin"; +export const BRAND_ADMIN: Permission = "admin"; + +export const CHIEF: Permission = "chief"; +export const MEMBER: Permission = "member"; + +export const TICKET_ADMIN: Permission = "ticket_admin"; +export const TICKET_CHECKIN: Permission = "ticket_checkin"; +export const INFO_ADMIN: Permission = "info_admin"; +export const COMPO_ADMIN: Permission = "compo_admin"; +export const NFC_ADMIN: Permission = "nfc_admin"; +export const HR_ADMIN: Permission = "hr_admin"; +export const CREW_CARD_PRINTER: Permission = "crew_card_printer"; + +export const TICKET_WHOLESALE: Permission = "ticket_wholesale"; +export const TICKET_BYPASS_TICKETSALE_START_RESTRICTION: Permission = "ticket_bypass_ticketsale_start_restriction"; + +export const globalRole = (permission: Permission) => `global:${permission}`; +export const brandRole = (brandUuid: string, permission: Permission) => `brand:${brandUuid}:${permission}`; + +const has = (payload: JWTPayload, role: string) => payload.roles.indexOf(role) !== -1; + +export const hasGlobalRole = (payload: JWTPayload, permission: Permission) => + has(payload, globalRole(permission)); + +export const hasBrandRole = (payload: JWTPayload, brandUuid: string, permission: Permission) => + has(payload, brandRole(brandUuid, permission)); + +export const isAdmin = (payload: JWTPayload) => hasGlobalRole(payload, ADMIN); + +export const isBrandAdmin = (payload: JWTPayload, brandUuid: string) => + hasBrandRole(payload, brandUuid, BRAND_ADMIN); + +export const isMemberOfAnyCrew = (payload: JWTPayload) => has(payload, MEMBER); + +export const isMemberOfBrand = (payload: JWTPayload, brandUuid: string) => + hasBrandRole(payload, brandUuid, MEMBER); + +export const isChiefOfAnyCrew = (payload: JWTPayload) => has(payload, CHIEF); + +export const isChiefOfBrand = (payload: JWTPayload, brandUuid: string) => + hasBrandRole(payload, brandUuid, CHIEF); + +export const isChiefOfCrew = (payload: JWTPayload, crewUuid: string) => + has(payload, `chief:${crewUuid}`); + +export const getBrandsWhere = (payload: JWTPayload, permission: Permission): Array => { + const suffix = `:${permission}`; + return payload.roles + .filter(role => role.startsWith("brand:") && role.endsWith(suffix)) + .map(role => role.slice("brand:".length, role.length - suffix.length)) + .filter(brandUuid => brandUuid.length > 0 && brandUuid.indexOf(":") === -1); +} + +export const getUserUuid = (payload: JWTPayload): string | null => { + const role = payload.roles.find(entry => entry.startsWith("user:")); + return role ? role.slice("user:".length) : null; +} diff --git a/src/seatmap/index.ts b/src/seatmap/index.ts index 9c16ad9..5a73dee 100644 --- a/src/seatmap/index.ts +++ b/src/seatmap/index.ts @@ -12,10 +12,12 @@ interface SeatmapBase { interface SeatmapBackground { uuid: string; + event_brand_uuid: string; url: string; } export type Seatmap = { + event_brand_uuid: string; name: string; description: string; background: SeatmapBackground|null; @@ -28,7 +30,7 @@ export type SeatmapAvailability = { rows: Array; } & SeatmapBase; -export const createSeatmap = async (name: string, description: string) => { +export const createSeatmap = async (event_brand_uuid: string, name: string, description: string) => { const response = await fetch(`${getApiServer()}/seatmap`, { method: 'PUT', headers: { @@ -37,7 +39,8 @@ export const createSeatmap = async (name: string, description: string) => { }, body: JSON.stringify({ name, - description + description, + event_brand_uuid }) }); @@ -62,8 +65,8 @@ export const getSeatmap = async (uuid: string) => { return (await response.json()) as Seatmap; } -export const getSeatmapAvailability = async (uuid: string) => { - const response = await fetch(`${getApiServer()}/seatmap/${uuid}/availability`, { +export const getSeatmapAvailability = async (uuid: string, event_uuid: string) => { + const response = await fetch(`${getApiServer()}/seatmap/${uuid}/availability?event_uuid=${encodeURIComponent(event_uuid)}`, { method: 'GET', headers: { ...(await Oauth.getAuthHeaders()), @@ -92,6 +95,21 @@ export const getSeatmaps = async () => { return (await response.json()) as Array; } +export const getBrandSeatmaps = async (event_brand_uuid: string) => { + const response = await fetch(`${getApiServer()}/event_brand/${event_brand_uuid}/seatmap`, { + method: 'GET', + headers: { + ...(await Oauth.getAuthHeaders()), + }, + }); + + if (!response.ok) { + throw new ApiGetError('Unable to get seatmaps'); + } + + return (await response.json()) as Array; +} + export const addRow = async (seatmapUuid: string, rowNumber: number, x: number, y: number, horizontal: boolean, entrance?: string, ticketType?: string) => { const response = await fetch(`${getApiServer()}/seatmap/${seatmapUuid}/row`, { diff --git a/src/ticket/index.ts b/src/ticket/index.ts index 87cd2c5..31057da 100644 --- a/src/ticket/index.ts +++ b/src/ticket/index.ts @@ -137,26 +137,6 @@ export const revertTransfer = async (uuid: string) => { } -export const getTransferLog = async (ticket_id: number) => { - const response = await fetch(`${getApiServer()}/ticket/${ticket_id}/transfer_log`, { - method: 'GET', - headers: { - "Content-Type": "application/json", - ...(await Oauth.getAuthHeaders()), - } - }); - - if (response.status === 403) { - throw new ApiGetError("You do not have access to view ticket transfer log.") - } - else if (!response.ok) { - throw new ApiGetError((await response.json())['error']); - } - else { - return await response.json(); - } -} - export const checkInTicket = async (ticket_id: number, totp?: string) => { const response = await fetch(`${getApiServer()}/ticket/${ticket_id}/check_in${totp?"?totp="+totp:""}`, { method: 'POST', @@ -225,8 +205,8 @@ export const seatTicket = async (ticket_id: number, seatUuid: string) => { } } -export const createTicket = async (recipient: string, ticketType: string) => { - const response = await fetch(`${getApiServer()}/ticket`, { +export const createTicket = async (event_uuid: string, recipient: string, ticketType: string) => { + const response = await fetch(`${getApiServer()}/event/${event_uuid}/ticket`, { method: 'POST', headers: { "Content-Type": "application/json", diff --git a/src/ticketType/index.ts b/src/ticketType/index.ts index a40a00e..6991535 100644 --- a/src/ticketType/index.ts +++ b/src/ticketType/index.ts @@ -1,9 +1,10 @@ import {getApiServer} from "../meta"; import * as Oauth from "../user/oauth"; -import {ApiGetError} from "../errors"; +import {ApiGetError, ApiPostError} from "../errors"; export interface TicketType { uuid: string; + event_brand_uuid: string; name: string; price: number; refundable: boolean; @@ -27,4 +28,37 @@ export const getTicketTypes = async () => { } return (await response.json()) as Array; +} + +export interface NewTicketType { + name: string; + price: number; + description: string; + refundable: boolean; + seatable: boolean; + grants_admission: boolean; +} + +export const createTicketType = async (event_brand_uuid: string, ticketType: NewTicketType) => { + const response = await fetch(`${getApiServer()}/event_brand/${event_brand_uuid}/ticket_type`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + ...(await Oauth.getAuthHeaders()), + }, + body: JSON.stringify(ticketType) + }); + + if (!response.ok) { + let error = "" + try { + error = (await response.json())['error'] + } catch (e) { + throw new ApiPostError('Unable to create ticket type'); + } + + throw new ApiPostError(error); + } + + return (await response.json()) as TicketType; } \ No newline at end of file diff --git a/src/user/index.ts b/src/user/index.ts index 326a47a..8d4bc8a 100644 --- a/src/user/index.ts +++ b/src/user/index.ts @@ -84,22 +84,6 @@ export const getFriendships = async (uuid: string): Promise> = return (await response.json()) as Array; }; -export const getFriendRequests = async (uuid: string): Promise> => { - const response = await fetch(`${getApiServer()}/user/${uuid}/friend_requests`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - ...(await Oauth.getAuthHeaders()) - }, - }); - - if (!response.ok) { - throw new ApiGetError("Unable to get the user's active friend requests"); - } - - return (await response.json()) as Array; -}; - export const getOwnedTickets = async (uuid: string): Promise> => { const response = await fetch(`${getApiServer()}/user/${uuid}/owned_tickets`, { method: 'GET', @@ -148,8 +132,8 @@ export const getTicketVouchers = async (uuid: string): Promise; }; -export const getTicketTransfers = async (uuid: string): Promise> => { - const response = await fetch(`${getApiServer()}/user/${uuid}/ticket_transfers`, { +export const getTicketTransfers = async (uuid: string, event_uuid: string): Promise> => { + const response = await fetch(`${getApiServer()}/user/${uuid}/ticket_transfers?event_uuid=${encodeURIComponent(event_uuid)}`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -366,16 +350,6 @@ export const getDiscordMapping = async (uuid: string) => { return await response.json() as DiscordMapping; } -export const getCrewCard = async (uuid: string) => { - const response = await fetch(`${getApiServer()}/user/${uuid}/crew_card`, { - method: "GET", - headers: { - ...(await Oauth.getAuthHeaders()) - } - }) - return response -} - export const getAuthenticationUrl = (callback: string, clientId: string) => { return `${getApiServer()}/static/login.html?redirect_uri=${encodeURIComponent(callback)}&client_id=${encodeURIComponent(clientId)}` }