@@ -2,18 +2,19 @@ import { Request, Router } from 'express';
22import { identity } from 'lodash' ;
33
44import {
5- addAdProvidersForAllSites ,
6- getAdProvidersForAllSites ,
7- removeAdProvidersForAllSites ,
5+ adProvidersForAllSitesMethods ,
86 adProvidersMethods ,
97 adProvidersByDomainRulesMethods ,
108 AdProviderSelectorsRule ,
119 filterRules ,
1210 AdProvidersByDomainRule ,
1311 adProvidersCategoriesMethods
1412} from '../../advertising/external-ads' ;
15- import { basicAuth } from '../../middlewares/basic-auth.middleware' ;
16- import { addObjectStorageMethodsToRouter , withBodyValidation , withExceptionHandler } from '../../utils/express-helpers' ;
13+ import {
14+ addObjectStorageMethodsToRouter ,
15+ addSetStorageMethodsToRouter ,
16+ withExceptionHandler
17+ } from '../../utils/express-helpers' ;
1718import { isDefined , transformValues } from '../../utils/helpers' ;
1819import {
1920 nonEmptyStringsListSchema ,
@@ -204,35 +205,13 @@ export const adProvidersRouter = Router();
204205 * '500':
205206 * $ref: '#/components/responses/ErrorResponse'
206207 */
207- adProvidersRouter
208- . route ( '/all-sites' )
209- . get (
210- withExceptionHandler ( async ( _req , res ) => {
211- const providers = await getAdProvidersForAllSites ( ) ;
212-
213- res . status ( 200 ) . header ( 'Cache-Control' , 'public, max-age=300' ) . send ( providers ) ;
214- } )
215- )
216- . post (
217- basicAuth ,
218- withExceptionHandler (
219- withBodyValidation ( nonEmptyStringsListSchema , async ( req , res ) => {
220- const providersAddedCount = await addAdProvidersForAllSites ( req . body ) ;
221-
222- res . status ( 200 ) . send ( { message : `${ providersAddedCount } providers have been added` } ) ;
223- } )
224- )
225- )
226- . delete (
227- basicAuth ,
228- withExceptionHandler (
229- withBodyValidation ( nonEmptyStringsListSchema , async ( req , res ) => {
230- const providersRemovedCount = await removeAdProvidersForAllSites ( req . body ) ;
231-
232- res . status ( 200 ) . send ( { message : `${ providersRemovedCount } providers have been removed` } ) ;
233- } )
234- )
235- ) ;
208+ addSetStorageMethodsToRouter ( adProvidersRouter , {
209+ path : '/all-sites' ,
210+ methods : adProvidersForAllSitesMethods ,
211+ arrayValidationSchema : nonEmptyStringsListSchema ,
212+ successfulAdditionMessage : addedEntriesCount => `${ addedEntriesCount } providers have been added` ,
213+ successfulRemovalMessage : removedEntriesCount => `${ removedEntriesCount } providers have been removed`
214+ } ) ;
236215
237216/**
238217 * @swagger
0 commit comments