Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export class Configuration {
filter?: (file: KycFileBlob, userData: UserData) => boolean;
sort?: (a: KycFileBlob, b: KycFileBlob) => KycFileBlob;
handleFileNotFound?: (zip: JSZip, userData: UserData) => any | false;
selectAll?: boolean;
}[];
}[] = [
{
Expand All @@ -309,6 +310,13 @@ export class Configuration {
],
fileTypes: [ContentType.PDF],
},
{
name: (file: KycFileBlob) => `IdentDoc_${file.name.split('/').pop()?.split('.')[0] ?? 'unknown'}`,
prefixes: (userData: UserData) => [`user/${userData.id}/Identification`],
fileTypes: [ContentType.PNG, ContentType.JPEG, ContentType.JPG],
selectAll: true,
handleFileNotFound: () => true,
},
],
},
{
Expand Down
42 changes: 28 additions & 14 deletions src/subdomains/generic/user/models/user-data/user-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,15 @@ export class UserDataService {
continue;
}

for (const { name: fileNameFn, fileTypes, prefixes, filter, handleFileNotFound, sort } of fileConfig) {
for (const {
name: fileNameFn,
fileTypes,
prefixes,
filter,
handleFileNotFound,
sort,
selectAll,
} of fileConfig) {
const files = allFiles
.filter((f) => prefixes(userData).some((p) => f.path.startsWith(p)))
.filter((f) => !fileTypes || fileTypes.some((t) => f.contentType.startsWith(t)))
Expand All @@ -417,19 +425,25 @@ export class UserDataService {

if (checkOnly) continue;

const selectedFile = files.reduce((l, c) => (sort ? sort(l, c) : l.updated > c.updated ? l : c));

try {
const fileData = await this.documentService.downloadFile(
selectedFile.category,
userDataId,
selectedFile.type,
selectedFile.name,
);
const filePath = `${userDataId}-${fileNameFn?.(selectedFile) ?? name}.${selectedFile.name.split('.').pop()}`;
subFolder.file(filePath, fileData.data);
} catch {
errors.push({ userDataId, errorType: 'DownloadFailed', folder: folderName, details: selectedFile.name });
const selectedFiles = selectAll
? files
: [files.reduce((l, c) => (sort ? sort(l, c) : l.updated > c.updated ? l : c))];

for (const selectedFile of selectedFiles) {
try {
const fileData = await this.documentService.downloadFile(
selectedFile.category,
userDataId,
selectedFile.type,
selectedFile.name,
);
const filePath = `${userDataId}-${fileNameFn?.(selectedFile) ?? name}.${selectedFile.name
.split('.')
.pop()}`;
subFolder.file(filePath, fileData.data);
} catch {
errors.push({ userDataId, errorType: 'DownloadFailed', folder: folderName, details: selectedFile.name });
}
}
}
}
Expand Down
Loading