Skip to content

Commit

Permalink
add all hierarchy props to credential csv
Browse files Browse the repository at this point in the history
  • Loading branch information
freddieptf committed Mar 7, 2024
1 parent 66af6d9 commit 3188a11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/routes/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export default async function files(fastify: FastifyInstance) {
fastify.get('/files/credentials', async (req, reply) => {
const sessionCache: SessionCache = req.sessionCache;
const results = new Map<ContactType, String[][]>();
const hierarchyProps = new Map<ContactType, string[]>();
const places = sessionCache.getPlaces();
places.forEach(place => {
const parent = Config.getParentProperty(place.type);
const record = [
place.hierarchyProperties[parent.property_name],
...Object.values(place.hierarchyProperties),
place.name,
place.contact.properties.name,
place.contact.properties.phone,
Expand All @@ -37,12 +37,15 @@ export default async function files(fastify: FastifyInstance) {
const result = results.get(place.type) || [];
result.push(record);
results.set(place.type, result);
if (!hierarchyProps.has(place.type)) {
hierarchyProps.set(place.type, Object.keys(place.hierarchyProperties))
}
});
const zip = new JSZip();
results.forEach((places, contactType) => {
const parent = Config.getParentProperty(contactType);
const columns = [
parent.friendly_name,
...hierarchyProps.get(contactType)!!,
contactType.friendly,
'name',
'phone',
Expand Down
5 changes: 1 addition & 4 deletions src/services/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ export default class Place {

for (const hierarchyLevel of Config.getHierarchyWithReplacement(this.type)) {
const propertyName = hierarchyLevel.property_name;
delete this.hierarchyProperties[propertyName];
if (formData[`${hierarchyPrefix}${propertyName}`]) {
this.hierarchyProperties[propertyName] = formData[`${hierarchyPrefix}${propertyName}`];
}
this.hierarchyProperties[propertyName] = formData[`${hierarchyPrefix}${propertyName}`] ?? '';
}
}

Expand Down

0 comments on commit 3188a11

Please sign in to comment.