Skip to content

Commit

Permalink
Create an organization schema and use this schema when generating the…
Browse files Browse the repository at this point in the history
… pdf-file
  • Loading branch information
bjorkgard committed Jan 22, 2025
1 parent c8b14b5 commit 89831fa
Show file tree
Hide file tree
Showing 17 changed files with 919 additions and 207 deletions.
6 changes: 6 additions & 0 deletions src/localization/locales/sv/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
"label.pioneerService": "Pionjärtjänst",
"label.pioneers": "Pionjärer",
"label.presentMembers": "_____ av {{count}} döpta aktiva medlemmar är närvarande",
"label.preview": "Förhandsvisning",
"label.privileges": "Privilegier",
"label.public": "Församlingen är synlig för import",
"label.publisher": "Förkunnare",
Expand Down Expand Up @@ -447,6 +448,7 @@
"label.serviceMonth": "Tjänstemånad",
"label.servicegroup_internal_list": "Intern tjänstegruppslista",
"label.servicegroup_list": "Tjänstegruppslista",
"label.sortOrder": "Sortering",
"label.soundStage": "Ljud/Podium",
"label.specialPioneer": "Specialpionjär",
"label.specialPioneers": "Specialpionjärer",
Expand Down Expand Up @@ -534,6 +536,7 @@
"menu.monthlyCompletion": "Rapportsammanställning",
"menu.monthlyMeetings": "Mötesnärvaro",
"menu.monthlyReport": "Månadsrapport",
"menu.organizationSchema": "Organisationsschema",
"menu.publishers": "Förkunnare",
"menu.reporting": "Rapportering",
"menu.responsibilities": "Ansvarsområden",
Expand Down Expand Up @@ -566,6 +569,9 @@
"month.october": "oktober",
"month.oktober": "oktober",
"month.september": "september",
"organization.description": "Här kan du designa hur du vill att organisationsschemat skall se ut. Du väljer själv vilka Uppgifter som skall vara med i schemat och får direkt se vilken data som kommer att presenteras när du exporterar organisationsschemat.",
"organization.headline": "Organisationsschema",
"organization.notification.updated": "Organisationsschemat är uppdaterat och du kan exportera från huvudmenyn.",
"publishers.addHeadline": "Lägg till förkunnare",
"publishers.deleteReport.body": "Är du säker på att du vill radera den här rapporten?",
"publishers.deleteReport.headline": "Radera rapport",
Expand Down
4 changes: 3 additions & 1 deletion src/main/databases/baseStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
CircuitOverseer,
Export,
ImportantDate,
Organization,
Publisher,
Responsibility,
ServiceGroup,
Expand All @@ -34,7 +35,8 @@ export default class BaseStore<
| ServiceGroup
| ServiceYear
| Settings
| Template,
| Template
| Organization,
> {
filePath: string = ''
databaseInstance: Datastore<T>
Expand Down
23 changes: 23 additions & 0 deletions src/main/databases/organizationStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import BaseStore from './baseStore'
import type { Organization } from './schemas'

export default class OrganizationStore extends BaseStore<Organization> {
find(): Promise<Organization[]> {
return this.databaseInstance.find({})
}

delete(id: string): Promise<number> {
// options set to {} since the default for multi is false
return this.databaseInstance.remove({ _id: id }, {})
}

async upsert(data: Organization): Promise<number | undefined> {
const isValid: boolean = this.validate(data)

if (isValid)
return await this.databaseInstance.update({ identifier: data.identifier }, data, { upsert: true })

else
return undefined
}
}
72 changes: 72 additions & 0 deletions src/main/databases/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,78 @@ export interface CircuitOverseer extends Base {
city: string
}

export interface OrganizationResponsibility {
active: boolean
type: string
sortOrder: number
}

export interface OrganizationTask {
type: string
manager: string
assistant?: string
sortOrder: number
}

export interface OrganizationAppointment {
active: boolean
type: string
sortOrder: number
}

export interface Organization extends Base {
identifier: string
responsibilities: OrganizationResponsibility[]
tasks: OrganizationTask[]
appointments: OrganizationAppointment[]
}

const OrganizationResponsibilitySchema: JSONSchemaType<OrganizationResponsibility> = {
type: 'object',
properties: {
active: { type: 'boolean' },
type: { type: 'string' },
sortOrder: { type: 'number' },
},
required: ['active', 'type', 'sortOrder'],
}

const OrganizationTaskSchema: JSONSchemaType<OrganizationTask> = {
type: 'object',
properties: {
type: { type: 'string' },
manager: { type: 'string' },
assistant: { type: 'string', nullable: true },
sortOrder: { type: 'number' },
},
required: ['type', 'manager', 'sortOrder'],
}

const OrganizationAppointmentSchema: JSONSchemaType<OrganizationAppointment> = {
type: 'object',
properties: {
active: { type: 'boolean' },
type: { type: 'string' },
sortOrder: { type: 'number' },
},
required: ['active', 'type', 'sortOrder'],
}

export const OrganizationSchema: JSONSchemaType<Organization> = {
type: 'object',
properties: {
_id: { type: 'string', nullable: true },
identifier: { type: 'string' },
responsibilities: { type: 'array', items: OrganizationResponsibilitySchema },
tasks: { type: 'array', items: OrganizationTaskSchema },
appointments: { type: 'array', items: OrganizationAppointmentSchema },
createdAt: { type: 'object', format: 'custom-date-time', nullable: true, required: [] },
updatedAt: { type: 'object', format: 'custom-date-time', nullable: true, required: [] },
},
required: ['identifier'],
additionalProperties: false,
}

export const CircuitOverseerSchema: JSONSchemaType<CircuitOverseer> = {
type: 'object',
properties: {
Expand Down
Loading

0 comments on commit 89831fa

Please sign in to comment.