copetit / whereareyou

for our family
1 stars 1 forks source link

Feature/add validation pipe #16 #38

Closed copetit closed 2 years ago

copetit commented 2 years ago

いくつか使えそうなのvalidation decoratorを追加してみました。

[確認方法] Swaggerで以下のRequestBodyを使ってpostすると http://localhost:4000/doc/#/wau/WauController_createPosting

{
  "PetName": "eeevee",
  "PetSex": "不明",
  "PetAge": 101,
  "PetInfo": "かわいい",
  "Detail": "ふわふわなしっぽ",
  "LostDate": "2021-12",
  "Address": "hogehoge",
  "CreatedDate": "2021-12",
  "UpdateDate": "2021-12",
  "locationinfo": {
    "lat": "fake",
    "lng": "fake"  },
  "user": {
    "Password": "12345678",
    "MailAddress": "fake_string"
  },
  "contents": {
    "imageUrl": "['dummyImage@dummy.com', 'dummyImage2@dummy.com']",
    "videoUrl": "['dummyVideo@dummy.com', 'dummyVideo2@dummy.com']"
  }
}

このようなエラーが返ってきます。

{
  "statusCode": 400,
  "message": [
    "PetAge must not be greater than 100",
    "LostDate must be a Date instance",
    "CreatedDate must be a Date instance",
    "UpdateDate must be a Date instance",
    "locationinfo.lat must be a latitude string or number",
    "locationinfo.lng must be a longitude string or number",
    "user.MailAddress must be an email"
  ],
  "error": "Bad Request"
}

[やってないこと]