mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-14 08:53:11 +00:00
Preserve pledge history, type field signals, link plan demands, and record immutable ex-ante allocation decisions.
89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import type { RelationOption } from '@/components/campaign/RelationMultiSelect'
|
|
import type { CampaignUser } from '@/payload-types'
|
|
import { relationshipId } from '@/utilities/relationship'
|
|
|
|
export type ActionPlanRelationOption = RelationOption & {
|
|
municipalityId: number
|
|
}
|
|
|
|
/** Municipalities the actor may operate on (coordinator: all 436; advisor: administered). */
|
|
export const loadMunicipalityOptions = async (
|
|
payload: Payload,
|
|
user: CampaignUser,
|
|
): Promise<RelationOption[]> => {
|
|
const result = await payload.find({
|
|
collection: 'municipality',
|
|
depth: 0,
|
|
limit: 0,
|
|
pagination: false,
|
|
sort: 'name',
|
|
select: { name: true },
|
|
where: {},
|
|
user,
|
|
overrideAccess: false,
|
|
})
|
|
return result.docs.map((municipality) => ({ id: municipality.id, name: municipality.name }))
|
|
}
|
|
|
|
export const loadOrganizationOptions = async (
|
|
payload: Payload,
|
|
user: CampaignUser,
|
|
): Promise<RelationOption[]> => {
|
|
const result = await payload.find({
|
|
collection: 'organization',
|
|
depth: 0,
|
|
limit: 0,
|
|
pagination: false,
|
|
sort: 'name',
|
|
select: { name: true },
|
|
where: {},
|
|
user,
|
|
overrideAccess: false,
|
|
})
|
|
return result.docs.map((organization) => ({ id: organization.id, name: organization.name }))
|
|
}
|
|
|
|
export const loadActionPlanOptions = async (
|
|
payload: Payload,
|
|
user: CampaignUser,
|
|
): Promise<ActionPlanRelationOption[]> => {
|
|
const result = await payload.find({
|
|
collection: 'actionPlan',
|
|
depth: 0,
|
|
limit: 0,
|
|
pagination: false,
|
|
sort: 'title',
|
|
select: { title: true, municipality: true },
|
|
where: {},
|
|
user,
|
|
overrideAccess: false,
|
|
})
|
|
|
|
return result.docs.flatMap((plan) => {
|
|
const municipalityId = relationshipId(plan.municipality)
|
|
return municipalityId ? [{ id: plan.id, name: plan.title, municipalityId }] : []
|
|
})
|
|
}
|
|
|
|
export const loadStateDeputyOptions = async (
|
|
payload: Payload,
|
|
user: CampaignUser,
|
|
): Promise<RelationOption[]> => {
|
|
const result = await payload.find({
|
|
collection: 'stateDeputy',
|
|
depth: 0,
|
|
limit: 0,
|
|
pagination: false,
|
|
sort: 'name',
|
|
select: { name: true, party: true },
|
|
where: {},
|
|
user,
|
|
overrideAccess: false,
|
|
})
|
|
return result.docs.map((stateDeputy) => ({
|
|
id: stateDeputy.id,
|
|
name: stateDeputy.party ? `${stateDeputy.name} (${stateDeputy.party})` : stateDeputy.name,
|
|
}))
|
|
}
|