Skip to content

Commit

Permalink
fix: improvements to API
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Mar 22, 2024
1 parent b06fe1b commit bbcc338
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/app/src/electron/EverythingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class EverythingService implements ConvertToServerSide<IPCServerMethods>
public getProject(): Project {
return this.storage.getProject()
}
private getRundowns(): { rundownIds: string[] } {
public getRundowns(): { rundownIds: string[] } {
const rundowns = this.storage.getAllRundowns()
return { rundownIds: rundowns.map((r) => r.id) }
}
Expand Down
8 changes: 5 additions & 3 deletions apps/app/src/electron/api/ApiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ export class ApiServer {
return this.app.channel(RUNDOWN_CHANNEL_PREFIX + data.id)
})

this.app.service(ServiceName.PROJECTS).publish((_data: Project | ProjectBase, _context: HookContext) => {
return this.app.channel(PROJECTS_CHANNEL_PREFIX)
})
this.app
.service(ServiceName.PROJECTS)
.publish((_data: string | Project | ProjectBase, _context: HookContext) => {
return this.app.channel(PROJECTS_CHANNEL_PREFIX)
})

// --- legacy code, only for a rapid prototype
this.app.use(
Expand Down
14 changes: 12 additions & 2 deletions apps/app/src/electron/api/GroupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,23 @@ export class GroupService extends EventEmitter {
return result.result
}

async update(data: { rundownId: string; groupId: string; group: PartialDeep<Group> }): Promise<void> {
async update(
data: { rundownId: string; groupId: string; group: PartialDeep<Group> },
body?: unknown
): Promise<void> {
if ((data === null || typeof data === 'string') && body) data = body as any // fix for when called via REST

// TODO: access control
const result = await this.everythingService.updateGroup(data)
if (!result) throw new GeneralError()
}

async remove(data: { rundownId: string; groupId: string }): Promise<void> {
async remove(data: { rundownId: string; groupId: string } | `${string}:${string}`): Promise<void> {
if (typeof data === 'string') {
const [rundownId, groupId] = data.split(':')
data = { rundownId, groupId }
}

// TODO: access control
const result = await this.everythingService.deleteGroup(data)
if (!result) throw new GeneralError()
Expand Down
4 changes: 4 additions & 0 deletions apps/app/src/electron/api/ProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class ProjectService extends EventEmitter {
})
}

async find(): Promise<string[]> {
const project = this.everythingService.getProject()
return [project.id]
}
async get(_id: string): Promise<Project> {
return this.everythingService.getProject()
}
Expand Down
5 changes: 5 additions & 0 deletions apps/app/src/electron/api/RundownService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export class RundownService extends EventEmitter {
})
}

async find(_params: Params): Promise<string[]> {
// TODO: access control
const rundowns = this.everythingService.getRundowns()
return rundowns.rundownIds
}
async get(id: string, params: Params): Promise<Rundown> {
// TODO: access control
const rundown = this.everythingService.getRundown({ rundownId: id })
Expand Down
8 changes: 5 additions & 3 deletions apps/app/src/ipc/IPCAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ type ServiceKeyArrays = KeyArrays<ServiceTypes>
// those are the arrays of service methods exposed to the clients
export const ClientMethods: ServiceKeyArrays = {
[ServiceName.GROUPS]: [
'create',
'create', // POST
'update', // PUT
'remove', // DELETE
'duplicate',
'insert',
'move',
Expand All @@ -62,8 +64,6 @@ export const ClientMethods: ServiceKeyArrays = {
'stop',
'playNext',
'playPrev',
'remove',
'update',
],
[ServiceName.LEGACY]: [],
[ServiceName.PARTS]: [
Expand All @@ -83,6 +83,7 @@ export const ClientMethods: ServiceKeyArrays = {
'insertTimelineObjs',
],
[ServiceName.PROJECTS]: [
'find',
'get',
'create',
'update',
Expand All @@ -102,6 +103,7 @@ export const ClientMethods: ServiceKeyArrays = {
'acknowledgeUserAgreement',
],
[ServiceName.RUNDOWNS]: [
'find',
'get',
'create',
'remove',
Expand Down

0 comments on commit bbcc338

Please sign in to comment.