diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2024-01-04 03:07:56 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2024-01-04 03:07:56 +0000 |
| commit | 0d33de3744f612262c12d648cd7147a2ef238a36 (patch) | |
| tree | 285af0ed69169621228e252affdac958f016dab2 /src-migrate/pages/api/promotion-program | |
| parent | bb8ee26d89842b4f9b99b48f2a7cc464c6ecc4ee (diff) | |
| parent | 67398e6f10d6f7729d8f1ace7005ef13d32c5ddd (diff) | |
Merged in Feature/promotion-program (pull request #124)
Feature/promotion program
Diffstat (limited to 'src-migrate/pages/api/promotion-program')
| -rw-r--r-- | src-migrate/pages/api/promotion-program/[id].tsx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src-migrate/pages/api/promotion-program/[id].tsx b/src-migrate/pages/api/promotion-program/[id].tsx new file mode 100644 index 00000000..ba716e85 --- /dev/null +++ b/src-migrate/pages/api/promotion-program/[id].tsx @@ -0,0 +1,43 @@ +import { NextApiRequest, NextApiResponse } from "next"; +import { SolrResponse } from "~/common/types/solr"; +import moment from 'moment' + +const SOLR_HOST = process.env.SOLR_HOST as string + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const id = req.query.id as string + + if (req.method === 'GET') { + const queryParams = new URLSearchParams({ q: `id:${id}` }) + const response = await fetch(`${SOLR_HOST}/solr/promotion_programs/select?${queryParams.toString()}`) + const data: SolrResponse<any[]> = await response.json() + + if (data.response.numFound === 0) { + res.status(404).json({ error: 'Program not found' }) + return + } + + const program = await map(data.response.docs[0]) + + res.status(200).json({ data: program }) + } +} + +const map = async (program: any) => { + const data: any = {} + + data.id = program.id + data.name = program.name_s + data.start_time = program.start_time_s + data.end_time = program.end_time_s + data.applies_to = program.applies_to_s + data.time_left = (new Date(data.end_time).getTime() - new Date().getTime()) / 1000 + + // const duration = moment.duration(data.time_left, 'seconds') + // const days = duration.days() + // const hours = duration.hours() + // const minutes = duration.minutes() + // const seconds = duration.seconds() + + return data +}
\ No newline at end of file |
