diff --git a/src/admin/admin.controller.ts b/src/admin/admin.controller.ts index 03442f8e55e2210e3bf1fc52f96e0c4617ff3add..999c6d949ba0026bdc654d172dc703459030ed50 100644 --- a/src/admin/admin.controller.ts +++ b/src/admin/admin.controller.ts @@ -2,6 +2,7 @@ import { Body, Delete, Param } from '@nestjs/common'; import { Controller, Get, Post, UseGuards } from '@nestjs/common'; import { ApiOperation, ApiParam } from '@nestjs/swagger'; import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; +import { NewsletterSubscriptionDocument } from '../newsletter/newsletter-subscription.schema'; import { NewsletterService } from '../newsletter/newsletter.service'; import { StructuresService } from '../structures/services/structures.service'; import { Roles } from '../users/decorators/roles.decorator'; @@ -111,6 +112,13 @@ export class AdminController { else return this.newsletterService.findAll(); } + @UseGuards(JwtAuthGuard, RolesGuard) + @Roles('admin') + @Get('countNewsletterSubscriptions') + public async countNewsletterSubscriptions(): Promise<number> { + return this.newsletterService.countNewsletterSubscriptions(); + } + @UseGuards(JwtAuthGuard, RolesGuard) @Roles('admin') @Delete('newsletterSubscription/:email') diff --git a/src/newsletter/newsletter.service.ts b/src/newsletter/newsletter.service.ts index c1ca5efc0e07368586b7a3ac99c7248c43d8a85f..57dab32d153c9d0843eca5e005a49da16123853f 100644 --- a/src/newsletter/newsletter.service.ts +++ b/src/newsletter/newsletter.service.ts @@ -2,7 +2,7 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model, Types } from 'mongoose'; import { INewsletterSubscription } from './interface/newsletter-subscription.interface'; -import { NewsletterSubscription } from './newsletter-subscription.schema'; +import { NewsletterSubscription, NewsletterSubscriptionDocument } from './newsletter-subscription.schema'; @Injectable() export class NewsletterService { @@ -32,10 +32,14 @@ export class NewsletterService { return this.newsletterSubscriptionModel.findOne({ email: mail }).exec(); } - public async searchNewsletterSubscription(searchString: string) { + public async searchNewsletterSubscription(searchString: string): Promise<NewsletterSubscriptionDocument[]> { return this.newsletterSubscriptionModel.find({ email: new RegExp(searchString, 'i') }).exec(); } + public async countNewsletterSubscriptions(): Promise<number> { + return this.newsletterSubscriptionModel.countDocuments({}).exec(); + } + public async deleteOneEmail(mail: string): Promise<NewsletterSubscription | undefined> { const subscription = await this.newsletterSubscriptionModel.findOne({ email: mail }).exec(); if (!subscription) {