-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 162-merge-contacts
- Loading branch information
Showing
51 changed files
with
1,460 additions
and
1,008 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Config, ContactType } from '../config'; | ||
import SessionCache from '../services/session-cache'; | ||
import { stringify } from 'csv/sync'; | ||
|
||
type File = { | ||
filename: string; | ||
content: string; | ||
}; | ||
|
||
export default function getCredentialsFiles(sessionCache: SessionCache, contactTypes: ContactType[]): File[] { | ||
const files: File[] = []; | ||
for (const contactType of contactTypes) { | ||
const places = sessionCache.getPlaces({ type: contactType.name }); | ||
if (!places.length) { | ||
continue; | ||
} | ||
|
||
const rows = places.map((place) => [ | ||
...Object.values(place.hierarchyProperties).map(prop => prop.formatted), | ||
place.name, | ||
place.contact.properties.name?.formatted, | ||
place.contact.properties.phone?.formatted, | ||
place.userRoles.join(' '), | ||
place.creationDetails.username, | ||
place.creationDetails.password, | ||
]); | ||
|
||
const constraints = Config.getHierarchyWithReplacement(contactType); | ||
const props = Object.keys(places[0].hierarchyProperties) | ||
.map(prop => constraints.find(c => c.property_name === prop)!.friendly_name); | ||
const columns = [ | ||
...props, | ||
contactType.friendly, | ||
'name', | ||
'phone', | ||
'role', | ||
'username', | ||
'password', | ||
]; | ||
|
||
const content = stringify(rows, { | ||
columns, | ||
header: true, | ||
}); | ||
files.push({ | ||
filename: `${contactType.name}.csv`, | ||
content, | ||
}); | ||
} | ||
|
||
return files; | ||
} |
Oops, something went wrong.