| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 35 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { schema, rules as schemaRules, validator } from '@ioc:Adonis/Core/Validator' |
||
| 2 | import { RequestContract } from '@ioc:Adonis/Core/Request' |
||
| 3 | |||
| 4 | const AUTHORIZE = (): boolean => { |
||
| 5 | return true |
||
| 6 | } |
||
| 7 | |||
| 8 | const RULES = (): any => { |
||
| 9 | return schema.create({ |
||
| 10 | products: schema.array().members( |
||
| 11 | schema.object().members({ |
||
| 12 | product_id: schema.number([ |
||
| 13 | schemaRules.exists({ table: 'products', column: 'id' }) |
||
| 14 | ]), |
||
| 15 | quantity: schema.number(), |
||
| 16 | }) |
||
| 17 | ) |
||
| 18 | }) |
||
| 19 | } |
||
| 20 | |||
| 21 | export default class OrderRequest { |
||
| 22 | public static validate = async (request: RequestContract): Promise<any> => { |
||
| 23 | if (AUTHORIZE() === false) { |
||
| 24 | return { |
||
| 25 | errors: 'Unauthorized' |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | return await request.validate({ |
||
| 30 | schema: RULES(), |
||
| 31 | reporter: validator.reporters.api, //For APIs |
||
| 32 | }) |
||
| 33 | } |
||
| 34 | } |
||
| 35 |