(format: ImportType, filepath: string, options: OptionValues)
| 34 | ) {} |
| 35 | |
| 36 | async run(format: ImportType, filepath: string, options: OptionValues): Promise<Response> { |
| 37 | const organizationId = options.organizationid; |
| 38 | if (organizationId != null) { |
| 39 | const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); |
| 40 | if (!userId) { |
| 41 | return Response.badRequest("No user found."); |
| 42 | } |
| 43 | const organization = await firstValueFrom( |
| 44 | this.organizationService.organizations$(userId).pipe(getOrganizationById(organizationId)), |
| 45 | ); |
| 46 | |
| 47 | if (organization == null) { |
| 48 | return Response.badRequest( |
| 49 | `You do not belong to an organization with the ID of ${organizationId}. Check the organization ID and sync your vault.`, |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | if (!organization.canAccessImport) { |
| 54 | return Response.badRequest( |
| 55 | "You are not authorized to import into the provided organization.", |
| 56 | ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if (options.formats || false) { |
| 61 | return await this.list(); |
| 62 | } else { |
| 63 | return await this.import(format, filepath, organizationId, options); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | private async import( |
| 68 | format: ImportType, |
no test coverage detected