-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClothSize.js
40 lines (34 loc) · 1.12 KB
/
ClothSize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const express = require('express')
const router = express.Router()
const User = require('../models/User')
const SizeProfile = require('../models/SizeProfile')
const Closet = require('../models/Closet')
const axios = require('axios')
router.post('/cloth_size', async (req, res) => {
try {
const { userId, clothId } = req.body
const user = await User.findById(userId).populate('sizeProfile')
const sizeProfile = user.sizeProfile
const closet = await Closet.findById(clothId)
const length = sizeProfile.length
const shoulderWidth = sizeProfile.shoulderWidth
const chestWidth = sizeProfile.chestWidth
const imageUrl = closet.clothesUrl
const overfit = user.favoriteStyle.fit
const aiApiResponse = await axios.get(process.env.AI_CLOTH_SIZE_API_URL, {
params: {
length,
shoulderWidth,
chestWidth,
imageUrl,
overfit,
},
})
const recommendedSize = aiApiResponse.data.size
res.json({ size: recommendedSize })
} catch (error) {
console.error(error)
res.status(500).json({ message: 'Server error' })
}
})
module.exports = router