feat: add start_date and end_date fields to advertisements with transformation and display in forms
This commit is contained in:
@@ -15,10 +15,15 @@ type TParameters = {
|
||||
|
||||
export const createAdsRequest = async (parameters: TParameters) => {
|
||||
const { payload, ...restParameters } = parameters
|
||||
const transformedPayload = {
|
||||
...payload,
|
||||
start_date: new Date(payload.start_date).toISOString(),
|
||||
end_date: new Date(payload.end_date).toISOString(),
|
||||
}
|
||||
try {
|
||||
const { data } = await HttpServer(restParameters).post(
|
||||
'/api/ads/create',
|
||||
payload,
|
||||
transformedPayload,
|
||||
)
|
||||
return advertisementsResponseSchema.parse(data)
|
||||
} catch (error) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
import { HttpServer, type THttpServer } from '~/libs/http-server'
|
||||
import type { TAdsSchema } from '~/pages/form-advertisements'
|
||||
|
||||
const advertisementsResponseSchema = z.object({
|
||||
data: z.object({
|
||||
Message: z.string(),
|
||||
}),
|
||||
})
|
||||
|
||||
type TParameters = {
|
||||
payload: TAdsSchema
|
||||
} & THttpServer
|
||||
|
||||
export const updateAdsRequest = async (parameters: TParameters) => {
|
||||
const { payload, ...restParameters } = parameters
|
||||
const { id, ...restPayload } = payload
|
||||
const transformedPayload = {
|
||||
...restPayload,
|
||||
start_date: new Date(payload.start_date).toISOString(),
|
||||
end_date: new Date(payload.end_date).toISOString(),
|
||||
}
|
||||
try {
|
||||
const { data } = await HttpServer(restParameters).put(
|
||||
`/api/ads/${id}/update`,
|
||||
transformedPayload,
|
||||
)
|
||||
return advertisementsResponseSchema.parse(data)
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user