Updaed graphql api with ResolveField for download URL
This commit is contained in:
parent
ce2b318f2a
commit
0715991f97
|
|
@ -4,11 +4,13 @@ import type { FileUpload } from 'graphql-upload-ts';
|
|||
import { CasesService } from './cases.service';
|
||||
import { CaseLaw } from './entities/case-law.entity';
|
||||
import { CaseFileValidationPipe } from 'src/common/pipes/file-validation.pipe';
|
||||
import { StorageService } from 'src/common/storage/storage.service';
|
||||
|
||||
@Resolver(() => CaseLaw)
|
||||
export class CasesResolver {
|
||||
constructor(
|
||||
private readonly casesService: CasesService,
|
||||
private readonly storage: StorageService,
|
||||
) {}
|
||||
|
||||
|
||||
|
|
@ -20,6 +22,14 @@ export class CasesResolver {
|
|||
return this.casesService.findOne(id, caseNumber);
|
||||
}
|
||||
|
||||
@ResolveField(() => String, { name: 'downloadUrl', nullable: true })
|
||||
async getDownloadUrl(@Parent() caseLaw: CaseLaw): Promise<string | null> {
|
||||
const key = caseLaw.storageKey;
|
||||
if (!key) return null;
|
||||
|
||||
return this.storage.getPresignedUrl(key);
|
||||
}
|
||||
|
||||
@Mutation(() => CaseLaw)
|
||||
async uploadCase(
|
||||
@Args({ name: 'file', type: () => GraphQLUpload }, CaseFileValidationPipe)
|
||||
|
|
|
|||
Loading…
Reference in a new issue