49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
import * as Joi from 'joi';
|
|
|
|
import { AbstractActionHandler, AwsProperties, Format } from '../abstract-action.handler';
|
|
import { Action } from '../action.enum';
|
|
import { AttributesService } from '../aws-shared-entities/attributes.service';
|
|
import { TagsService } from '../aws-shared-entities/tags.service';
|
|
import { SqsQueueEntryService } from './sqs-queue-entry.service';
|
|
import { SqsQueue } from './sqs-queue.entity';
|
|
|
|
type QueryParams = {
|
|
QueueUrl?: string,
|
|
__path: string;
|
|
}
|
|
|
|
@Injectable()
|
|
export class DeleteQueueHandler extends AbstractActionHandler<QueryParams> {
|
|
|
|
constructor(
|
|
private readonly tagsService: TagsService,
|
|
private readonly attributeService: AttributesService,
|
|
private readonly sqsQueueEntryService: SqsQueueEntryService,
|
|
) {
|
|
super();
|
|
}
|
|
|
|
format = Format.Xml;
|
|
action = Action.SqsDeleteQueue;
|
|
validator = Joi.object<QueryParams, true>({
|
|
QueueUrl: Joi.string(),
|
|
__path: Joi.string().required(),
|
|
});
|
|
|
|
protected async handle(params: QueryParams) {
|
|
|
|
const [accountId, name] = SqsQueue.tryGetAccountIdAndNameFromPathOrArn(params.QueueUrl ?? params.__path);
|
|
const queue = await this.sqsQueueEntryService.findQueueByAccountIdAndName(accountId, name);
|
|
|
|
if (!queue) {
|
|
throw new BadRequestException('ResourceNotFoundException');
|
|
}
|
|
|
|
await this.sqsQueueEntryService.purge(accountId, name);
|
|
await this.tagsService.deleteByArn(queue.arn);
|
|
await this.attributeService.deleteByArn(queue.arn);
|
|
await this.sqsQueueEntryService.deleteQueue(queue.id);
|
|
}
|
|
}
|