11import { Application } from 'express' ;
22import { NextFunction , Request , Response } from '../http' ;
3- import { PopulateStrategy } from '../config/values' ;
3+ import { PopulateStrategy , ValidatorErrorCode } from '../config/values' ;
44import { AuthenticateAdmin } from '../middlewares/authentication' ;
55import { BatchUsers } from '../models/batch-users' ;
6- import { ValidationError } from '../lib/errors' ;
6+ import { ResourceError , ValidationError } from '../lib/errors' ;
77
88/**
99 * Installs new route on the provided application.
@@ -21,6 +21,30 @@ export function inject(app: Application) {
2121
2222export async function resolve ( req : Request , res : Response ) : Promise < void > {
2323 const { context, body } = req ;
24+
25+ const usersToCreate = body . users ;
26+
27+ const emailSet = new Set < string > ( ) ;
28+ const walletSet = new Set < string > ( ) ;
29+
30+ for ( const user of usersToCreate ) {
31+ const { email, wallet } = user ;
32+
33+ if ( email && emailSet . has ( email ) ) {
34+ throw new ResourceError ( ValidatorErrorCode . DUPLICATED_MAIL ) ;
35+ }
36+ if ( wallet && walletSet . has ( wallet ) ) {
37+ throw new ResourceError ( ValidatorErrorCode . DUPLICATED_WALLET ) ;
38+ }
39+
40+ if ( email ) {
41+ emailSet . add ( email ) ;
42+ }
43+ if ( wallet ) {
44+ walletSet . add ( wallet ) ;
45+ }
46+ }
47+
2448 const users = new BatchUsers ( { } , context ) . populate (
2549 body ,
2650 PopulateStrategy . ADMIN ,
0 commit comments