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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DatasetDownloadRequestPipe } from './pipes/dataset-download-request.pip
import { BasicCsvTransformer } from './pipes/csv/basic-field.pipe';
import { VideoCsvTransformer } from './pipes/csv/video-field.pipe';
import { UserModule } from '../user/user.module';
import { LexiconCsvTransformer } from './pipes/csv/lexicon-field.pipe';

@Module({
imports: [
Expand Down Expand Up @@ -48,7 +49,8 @@ import { UserModule } from '../user/user.module';
StudyDownloadRequestPipe,
DatasetDownloadRequestPipe,
BasicCsvTransformer,
VideoCsvTransformer
VideoCsvTransformer,
LexiconCsvTransformer
]
})
export class DownloadRequestModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Injectable, PipeTransform } from '@nestjs/common';
import { CsvFieldTest } from '../../../download-request/types/csv-field';

@Injectable()
export class LexiconCsvTransformer implements PipeTransform<any, Promise<string>> {
async transform(value: any): Promise<string> {
if (!value) {
return '';
}

return value.key;
}
}

export const lexiconCsvTest: CsvFieldTest = (uischema, _schema) => {
if (uischema.options?.customType === 'asl-lex') {
return true;
}
return false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { videoCsvTest, VideoCsvTransformer } from '../pipes/csv/video-field.pipe
import { basicCsvTest, BasicCsvTransformer } from '../pipes/csv/basic-field.pipe';
import { StudyService } from '../../study/study.service';
import { UserService } from '../../user/user.service';
import { lexiconCsvTest, LexiconCsvTransformer } from '../pipes/csv/lexicon-field.pipe';

@Injectable()
export class StudyDownloadService {
Expand All @@ -45,7 +46,8 @@ export class StudyDownloadService {
private readonly basicCsvTransformer: BasicCsvTransformer,
private readonly videoCsvTransformer: VideoCsvTransformer,
private readonly studyService: StudyService,
private readonly userService: UserService
private readonly userService: UserService,
private readonly lexiconCsvTransformer: LexiconCsvTransformer
) {}

async createDownloadRequest(
Expand Down Expand Up @@ -369,6 +371,18 @@ export class StudyDownloadService {
}
});
}
} else if (lexiconCsvTest(uiSchema, dataSchema)) {
csvFields.push({
header: propertyName,
convertField: async (tag) => {
const tagField = tag.data?.find((field) => field.name == propertyName);
if (!tagField) {
throw new Error(`Tag field ${propertyName} not found`);
}

return await this.lexiconCsvTransformer.transform(tagField.data);
}
});
} else if (basicCsvTest(uiSchema, dataSchema)) {
csvFields.push({
header: propertyName,
Expand Down