Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix request body randomID to Array #112

Merged
merged 1 commit into from
May 6, 2020
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
15 changes: 12 additions & 3 deletions src/users/dto/delete-user-organization.dto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { ApiPropertyOptional } from '@nestjs/swagger'
import { IsString, IsOptional, IsNotEmpty } from 'class-validator'
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { IsString, IsOptional, IsNotEmpty, IsArray, ValidateNested } from 'class-validator'
import { Type } from 'class-transformer'

export class DeleteUserOrganizationDto {
export class RandomIDDto {
@ApiPropertyOptional()
@IsOptional()
@IsString()
@IsNotEmpty()
randomID: string
}

export class DeleteUserOrganizationDto {
@ApiProperty({ type: RandomIDDto, isArray: true })
@IsArray()
@ValidateNested({ each: true })
@Type(() => RandomIDDto)
randomIDs: RandomIDDto[]

// Keys without any decorators are non-Whitelisted. Validator will throw error if it's passed in payload.
userId: string
Expand Down
28 changes: 16 additions & 12 deletions src/users/users.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,27 @@ export class UsersRepository {
async deleteDiagnosisKeysForOrg(
deleteUserOrganization: DeleteUserOrganizationDto
): Promise<void> {
const { organizationCode, randomID } = deleteUserOrganization
const { organizationCode, randomIDs } = deleteUserOrganization

if (!randomID) {
if (randomIDs.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, it's also possible to do this way, of course both ways will give same result! 🙏

if(!randomIDs.length)

return
}

await (await this.firestoreDB)
.collection('diagnosisKeysForOrg')
.doc(organizationCode)
.collection('tempIDs')
.where('randomID', '==', randomID)
.get()
.then((query) => {
query.forEach((doc) => {
doc.ref.delete()
})
await Promise.all(
randomIDs.map(async ({ randomID }) => {
await (await this.firestoreDB)
.collection('diagnosisKeysForOrg')
.doc(organizationCode)
.collection('tempIDs')
.where('randomID', '==', randomID)
.get()
.then((query) => {
query.forEach((doc) => {
doc.ref.delete()
})
})
})
)
}

async createDiagnosisKeysForOrg(
Expand Down