app/Requests/LoginRequest.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 35
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 24
mnd 1
bc 1
fnc 1
dl 0
loc 35
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A LoginRequest.validate 0 10 2
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
    email: schema.string({ trim: true }, [
11
      schemaRules.email(),
12
      schemaRules.exists({ table: 'users', column: 'email' })
13
    ]),
14
    password: schema.string({ trim: true }, [
15
      schemaRules.minLength(8),
16
      schemaRules.maxLength(150)
17
    ]),
18
  })
19
}
20
21
export default class LoginRequest {
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