-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.ts
50 lines (42 loc) · 1.39 KB
/
route.ts
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
41
42
43
44
45
46
47
48
49
50
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/medusa"
import ProductVideoService from "../../../../services/product-video"
// get video id by product id
// create video. passing in product id
export const GET = async (
req: MedusaRequest,
res: MedusaResponse
) => {
console.log('here in video embed', req.query);
const productId = req.params.productId
if (!productId) {
return res.status(400).json({ message: "no product id supplied" })
}
const productVideoService = req.scope.resolve<ProductVideoService>(
"productVideoService"
)
const productVideo = await productVideoService.getVideoByProductId(productId);
if (!productVideo) {
return res.status(200).json(null)
}
res.json(productVideo);
}
export const POST = async (
req: MedusaRequest<{ productId: string, videoId: string }>,
res: MedusaResponse
) => {
const productId = req.params.productId
const videoId = req.body.videoId
console.log('productId', productId)
console.log('videoId', videoId)
const productVideoService = req.scope.resolve<ProductVideoService>(
"productVideoService"
)
const newProductVideo = await productVideoService.storeVideo(productId, videoId);
if (!newProductVideo) {
return res.status(500).json({ message: "failed to create product video" });
}
res.json(newProductVideo);
}