| 
									
										
										
										
											2020-05-14 11:57:43 +02:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-21 13:20:57 +02:00
										 |  |  | const { isUndefined } = require('lodash/fp'); | 
					
						
							| 
									
										
										
										
											2021-11-03 19:31:57 +01:00
										 |  |  | const { yup, validateYupSchema } = require('@strapi/utils'); | 
					
						
							| 
									
										
										
										
											2020-05-18 19:54:43 +02:00
										 |  |  | const validators = require('./common-validators'); | 
					
						
							| 
									
										
										
										
											2020-05-14 11:57:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 17:16:49 +02:00
										 |  |  | const userCreationSchema = yup | 
					
						
							|  |  |  |   .object() | 
					
						
							|  |  |  |   .shape({ | 
					
						
							| 
									
										
										
										
											2020-05-18 20:39:39 +02:00
										 |  |  |     email: validators.email.required(), | 
					
						
							|  |  |  |     firstname: validators.firstname.required(), | 
					
						
							| 
									
										
										
										
											2021-11-10 18:36:07 +01:00
										 |  |  |     lastname: validators.lastname, | 
					
						
							| 
									
										
										
										
											2020-07-09 18:10:16 +02:00
										 |  |  |     roles: validators.roles.min(1), | 
					
						
							| 
									
										
										
										
											2021-02-05 16:35:47 +01:00
										 |  |  |     preferedLanguage: yup.string().nullable(), | 
					
						
							| 
									
										
										
										
											2020-05-18 17:16:49 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  |   .noUnknown(); | 
					
						
							| 
									
										
										
										
											2020-05-14 11:57:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 19:54:43 +02:00
										 |  |  | const profileUpdateSchema = yup | 
					
						
							|  |  |  |   .object() | 
					
						
							|  |  |  |   .shape({ | 
					
						
							| 
									
										
										
										
											2020-06-04 10:25:02 +02:00
										 |  |  |     email: validators.email.notNull(), | 
					
						
							|  |  |  |     firstname: validators.firstname.notNull(), | 
					
						
							| 
									
										
										
										
											2021-11-10 18:36:07 +01:00
										 |  |  |     lastname: validators.lastname.nullable(), | 
					
						
							| 
									
										
										
										
											2020-05-27 16:06:15 +02:00
										 |  |  |     username: validators.username.nullable(), | 
					
						
							| 
									
										
										
										
											2020-06-04 10:25:02 +02:00
										 |  |  |     password: validators.password.notNull(), | 
					
						
							| 
									
										
										
										
											2021-10-21 13:20:57 +02:00
										 |  |  |     currentPassword: yup | 
					
						
							|  |  |  |       .string() | 
					
						
							|  |  |  |       .when('password', (password, schema) => (!isUndefined(password) ? schema.required() : schema)) | 
					
						
							|  |  |  |       .notNull(), | 
					
						
							| 
									
										
										
										
											2021-02-05 16:35:47 +01:00
										 |  |  |     preferedLanguage: yup.string().nullable(), | 
					
						
							| 
									
										
										
										
											2020-05-18 19:54:43 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  |   .noUnknown(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-27 16:06:15 +02:00
										 |  |  | const userUpdateSchema = yup | 
					
						
							|  |  |  |   .object() | 
					
						
							|  |  |  |   .shape({ | 
					
						
							| 
									
										
										
										
											2020-06-04 10:25:02 +02:00
										 |  |  |     email: validators.email.notNull(), | 
					
						
							|  |  |  |     firstname: validators.firstname.notNull(), | 
					
						
							| 
									
										
										
										
											2021-11-10 18:36:07 +01:00
										 |  |  |     lastname: validators.lastname.nullable(), | 
					
						
							| 
									
										
										
										
											2020-05-27 16:06:15 +02:00
										 |  |  |     username: validators.username.nullable(), | 
					
						
							| 
									
										
										
										
											2020-06-04 10:25:02 +02:00
										 |  |  |     password: validators.password.notNull(), | 
					
						
							|  |  |  |     isActive: yup.bool().notNull(), | 
					
						
							|  |  |  |     roles: validators.roles.min(1).notNull(), | 
					
						
							| 
									
										
										
										
											2020-05-27 16:06:15 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  |   .noUnknown(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 15:46:59 +02:00
										 |  |  | const usersDeleteSchema = yup | 
					
						
							|  |  |  |   .object() | 
					
						
							|  |  |  |   .shape({ | 
					
						
							|  |  |  |     ids: yup | 
					
						
							|  |  |  |       .array() | 
					
						
							|  |  |  |       .of(yup.strapiID()) | 
					
						
							|  |  |  |       .min(1) | 
					
						
							|  |  |  |       .required(), | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   .noUnknown(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 11:57:43 +02:00
										 |  |  | module.exports = { | 
					
						
							| 
									
										
										
										
											2021-11-03 19:31:57 +01:00
										 |  |  |   validateUserCreationInput: validateYupSchema(userCreationSchema), | 
					
						
							|  |  |  |   validateProfileUpdateInput: validateYupSchema(profileUpdateSchema), | 
					
						
							|  |  |  |   validateUserUpdateInput: validateYupSchema(userUpdateSchema), | 
					
						
							|  |  |  |   validateUsersDeleteInput: validateYupSchema(usersDeleteSchema), | 
					
						
							| 
									
										
										
										
											2021-02-10 11:57:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   schemas: { | 
					
						
							|  |  |  |     userCreationSchema, | 
					
						
							|  |  |  |     usersDeleteSchema, | 
					
						
							|  |  |  |     userUpdateSchema, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-05-14 11:57:43 +02:00
										 |  |  | }; |