Skip to content

Commit

Permalink
feat: add programOutput tag to line (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saelmala authored Dec 19, 2024
1 parent 8fa0111 commit 2db316f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
12 changes: 9 additions & 3 deletions src/api_productions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
} else {
await productionManager.addProductionLine(
production,
request.body.name
request.body.name,
request.body.programOutputLine || false
);
const allLinesResponse: LineResponse[] =
coreFunctions.getAllLinesResponse(production);
Expand Down Expand Up @@ -362,7 +363,8 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
name: line.name,
id: line.id,
smbConferenceId: line.smbConferenceId,
participants: participantlist
participants: participantlist,
programOutputLine: line.programOutputLine || false
};
reply.code(200).send(lineResponse);
}
Expand Down Expand Up @@ -428,7 +430,11 @@ const apiProductions: FastifyPluginCallback<ApiProductionsOptions> = (
message: `Failed to update line with id ${lineId} in production ${productionId}`
});
} else {
reply.code(200).send({ name: request.body.name, id: lineId });
reply.code(200).send({
name: request.body.name,
id: lineId,
programOutputLine: line.programOutputLine || false
});
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/api_productions_core_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,15 @@ export class CoreFunctions {

getAllLinesResponse(production: Production): LineResponse[] {
const allLinesResponse: LineResponse[] = production.lines.map(
({ name, id, smbConferenceId }) => ({
({ name, id, smbConferenceId, programOutputLine }) => ({
name,
id,
smbConferenceId,
participants: this.productionManager.getUsersForLine(
production._id.toString(),
id
)
),
programOutputLine
})
);
return allLinesResponse;
Expand Down
12 changes: 8 additions & 4 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ export const NewProduction = Type.Object({
name: Type.String(),
lines: Type.Array(
Type.Object({
name: Type.String()
name: Type.String(),
programOutputLine: Type.Optional(Type.Boolean())
})
)
});

export const NewProductionLine = Type.Object({
name: Type.String()
name: Type.String(),
programOutputLine: Type.Optional(Type.Boolean())
});

const SmbCandidate = Type.Object({
Expand Down Expand Up @@ -173,14 +175,16 @@ export const UserSession = Type.Object({
export const Line = Type.Object({
name: Type.String(),
id: Type.String(),
smbConferenceId: Type.String()
smbConferenceId: Type.String(),
programOutputLine: Type.Optional(Type.Boolean())
});

export const LineResponse = Type.Object({
name: Type.String(),
id: Type.String(),
smbConferenceId: Type.String(),
participants: Type.Array(UserResponse)
participants: Type.Array(UserResponse),
programOutputLine: Type.Optional(Type.Boolean())
});

export const PatchLine = Type.Omit(Line, ['id', 'smbConferenceId']);
Expand Down
7 changes: 6 additions & 1 deletion src/production_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ describe('production_manager', () => {
const productionManagerTest = new ProductionManager(dbManager);
const production = await productionManagerTest.getProduction(1);
if (production) {
await productionManagerTest.addProductionLine(production, 'newName');
await productionManagerTest.addProductionLine(
production,
'newName',
false
);
expect(dbManager.updateProduction).toHaveBeenLastCalledWith({
_id: 1,
name: 'productionname',
Expand All @@ -282,6 +286,7 @@ describe('production_manager', () => {
},
{
name: 'newName',
programOutputLine: false,
id: '2',
smbConferenceId: ''
}
Expand Down
9 changes: 6 additions & 3 deletions src/production_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export class ProductionManager extends EventEmitter {
const newProductionLine: Line = {
name: line.name,
id: index.toString(),
smbConferenceId: ''
smbConferenceId: '',
programOutputLine: line.programOutputLine || false
};
newProductionLines.push(newProductionLine);
}
Expand All @@ -76,7 +77,8 @@ export class ProductionManager extends EventEmitter {

async addProductionLine(
production: Production,
newLineName: string
newLineName: string,
programOutputLine: boolean
): Promise<Production | undefined> {
const nextLineId = production.lines.length
? Math.max(...production.lines.map((line) => parseInt(line.id, 10))) + 1
Expand All @@ -85,7 +87,8 @@ export class ProductionManager extends EventEmitter {
production.lines.push({
name: newLineName,
id: nextLineId.toString(),
smbConferenceId: ''
smbConferenceId: '',
programOutputLine: programOutputLine || false
});

return this.dbManager.updateProduction(production);
Expand Down

0 comments on commit 2db316f

Please sign in to comment.