chore: baseline import
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import config from '@payload-config'
|
||||
import {
|
||||
REST_DELETE,
|
||||
REST_GET,
|
||||
REST_OPTIONS,
|
||||
REST_PATCH,
|
||||
REST_POST,
|
||||
REST_PUT,
|
||||
} from '@payloadcms/next/routes'
|
||||
|
||||
export const GET = REST_GET(config)
|
||||
export const POST = REST_POST(config)
|
||||
export const DELETE = REST_DELETE(config)
|
||||
export const PATCH = REST_PATCH(config)
|
||||
export const PUT = REST_PUT(config)
|
||||
export const OPTIONS = REST_OPTIONS(config)
|
||||
@@ -0,0 +1,104 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { getPayloadClient } from '@/lib/payload'
|
||||
import type { DistributorRequest } from '@/payload-types'
|
||||
|
||||
type SubmissionPayload = {
|
||||
companyName?: string
|
||||
contactName?: string
|
||||
country?: string
|
||||
distributionExperience?: string
|
||||
email?: string
|
||||
message?: string
|
||||
phone?: string
|
||||
publicWebsite?: string
|
||||
startedAt?: number
|
||||
website?: string
|
||||
}
|
||||
|
||||
function normalizeText(value: unknown) {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function toRichText(value: string): NonNullable<DistributorRequest['message']> | null {
|
||||
if (!value) return null
|
||||
|
||||
return {
|
||||
root: {
|
||||
children: [
|
||||
{
|
||||
children: [{ text: value, type: 'text', version: 1 }],
|
||||
direction: null,
|
||||
format: '',
|
||||
indent: 0,
|
||||
type: 'paragraph',
|
||||
version: 1,
|
||||
},
|
||||
],
|
||||
direction: null,
|
||||
format: '',
|
||||
indent: 0,
|
||||
type: 'root',
|
||||
version: 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const payload = await getPayloadClient()
|
||||
const body = (await request.json()) as SubmissionPayload
|
||||
|
||||
const companyName = normalizeText(body.companyName)
|
||||
const contactName = normalizeText(body.contactName)
|
||||
const email = normalizeText(body.email)
|
||||
const country = normalizeText(body.country)
|
||||
const phone = normalizeText(body.phone)
|
||||
const distributionExperience = normalizeText(body.distributionExperience)
|
||||
const publicWebsite = normalizeText(body.publicWebsite)
|
||||
const message = normalizeText(body.message)
|
||||
const website = normalizeText(body.website)
|
||||
const startedAt = typeof body.startedAt === 'number' ? body.startedAt : 0
|
||||
|
||||
if (website) {
|
||||
return NextResponse.json({ message: 'Ignored.' }, { status: 200 })
|
||||
}
|
||||
|
||||
if (startedAt && Date.now() - startedAt < 2500) {
|
||||
return NextResponse.json({ error: 'Submission was too fast to be valid.' }, { status: 400 })
|
||||
}
|
||||
|
||||
if (!companyName || !contactName || !email || !country) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Company name, contact name, email, and country are required.' },
|
||||
{ status: 400 },
|
||||
)
|
||||
}
|
||||
|
||||
await payload.create({
|
||||
collection: 'distributorRequests',
|
||||
data: {
|
||||
companyName,
|
||||
contactName,
|
||||
country,
|
||||
distributionExperience: distributionExperience || undefined,
|
||||
email,
|
||||
message: toRichText(message) || undefined,
|
||||
phone: phone || undefined,
|
||||
website: publicWebsite || undefined,
|
||||
status: 'draft',
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Your distributor request has been submitted successfully.',
|
||||
ok: true,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Distributor request submission failed', error)
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Unable to submit the distributor request right now.' },
|
||||
{ status: 500 },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { getPayloadClient } from '@/lib/payload'
|
||||
import type { OemRequest } from '@/payload-types'
|
||||
|
||||
type SubmissionPayload = {
|
||||
companyName?: string
|
||||
contactName?: string
|
||||
country?: string
|
||||
email?: string
|
||||
message?: string
|
||||
phone?: string
|
||||
projectType?: string
|
||||
startedAt?: number
|
||||
website?: string
|
||||
}
|
||||
|
||||
function normalizeText(value: unknown) {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function toRichText(value: string): NonNullable<OemRequest['message']> | null {
|
||||
if (!value) return null
|
||||
|
||||
return {
|
||||
root: {
|
||||
children: [
|
||||
{
|
||||
children: [{ text: value, type: 'text', version: 1 }],
|
||||
direction: null,
|
||||
format: '',
|
||||
indent: 0,
|
||||
type: 'paragraph',
|
||||
version: 1,
|
||||
},
|
||||
],
|
||||
direction: null,
|
||||
format: '',
|
||||
indent: 0,
|
||||
type: 'root',
|
||||
version: 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const payload = await getPayloadClient()
|
||||
const body = (await request.json()) as SubmissionPayload
|
||||
|
||||
const companyName = normalizeText(body.companyName)
|
||||
const contactName = normalizeText(body.contactName)
|
||||
const email = normalizeText(body.email)
|
||||
const country = normalizeText(body.country)
|
||||
const phone = normalizeText(body.phone)
|
||||
const projectType = normalizeText(body.projectType)
|
||||
const message = normalizeText(body.message)
|
||||
const website = normalizeText(body.website)
|
||||
const startedAt = typeof body.startedAt === 'number' ? body.startedAt : 0
|
||||
|
||||
if (website) {
|
||||
return NextResponse.json({ message: 'Ignored.' }, { status: 200 })
|
||||
}
|
||||
|
||||
if (startedAt && Date.now() - startedAt < 2500) {
|
||||
return NextResponse.json({ error: 'Submission was too fast to be valid.' }, { status: 400 })
|
||||
}
|
||||
|
||||
if (!companyName || !contactName || !email || !message) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Company name, contact name, email, and project brief are required.' },
|
||||
{ status: 400 },
|
||||
)
|
||||
}
|
||||
|
||||
const richMessage = toRichText(message)
|
||||
if (!richMessage) {
|
||||
return NextResponse.json({ error: 'Project brief is required.' }, { status: 400 })
|
||||
}
|
||||
|
||||
await payload.create({
|
||||
collection: 'oemRequests',
|
||||
data: {
|
||||
companyName,
|
||||
contactName,
|
||||
country: country || undefined,
|
||||
email,
|
||||
message: richMessage,
|
||||
phone: phone || undefined,
|
||||
projectType: projectType || undefined,
|
||||
status: 'draft',
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Your OEM inquiry has been submitted successfully.',
|
||||
ok: true,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('OEM inquiry submission failed', error)
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Unable to submit the OEM inquiry right now.' },
|
||||
{ status: 500 },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { getPayloadClient } from '@/lib/payload'
|
||||
import type { AfterServiceRequest } from '@/payload-types'
|
||||
|
||||
type SubmissionPayload = {
|
||||
country?: string
|
||||
details?: string
|
||||
email?: string
|
||||
issueSummary?: string
|
||||
name?: string
|
||||
productModel?: string
|
||||
purchaseDate?: string
|
||||
serialNumber?: string
|
||||
startedAt?: number
|
||||
website?: string
|
||||
}
|
||||
|
||||
function normalizeText(value: unknown) {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function toRichText(value: string): NonNullable<AfterServiceRequest['details']> | null {
|
||||
if (!value) return null
|
||||
|
||||
const richText: NonNullable<AfterServiceRequest['details']> = {
|
||||
root: {
|
||||
children: [
|
||||
{
|
||||
children: [{ text: value, type: 'text', version: 1 }],
|
||||
direction: null,
|
||||
format: '',
|
||||
indent: 0,
|
||||
type: 'paragraph',
|
||||
version: 1,
|
||||
},
|
||||
],
|
||||
direction: null,
|
||||
format: '',
|
||||
indent: 0,
|
||||
type: 'root',
|
||||
version: 1,
|
||||
},
|
||||
}
|
||||
|
||||
return richText
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const payload = await getPayloadClient()
|
||||
const body = (await request.json()) as SubmissionPayload
|
||||
|
||||
const name = normalizeText(body.name)
|
||||
const email = normalizeText(body.email)
|
||||
const issueSummary = normalizeText(body.issueSummary)
|
||||
const country = normalizeText(body.country)
|
||||
const productModel = normalizeText(body.productModel)
|
||||
const serialNumber = normalizeText(body.serialNumber)
|
||||
const purchaseDate = normalizeText(body.purchaseDate)
|
||||
const details = normalizeText(body.details)
|
||||
const website = normalizeText(body.website)
|
||||
const startedAt = typeof body.startedAt === 'number' ? body.startedAt : 0
|
||||
|
||||
if (website) {
|
||||
return NextResponse.json({ message: 'Ignored.' }, { status: 200 })
|
||||
}
|
||||
|
||||
if (startedAt && Date.now() - startedAt < 2500) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Submission was too fast to be valid.' },
|
||||
{ status: 400 },
|
||||
)
|
||||
}
|
||||
|
||||
if (!name || !email || !issueSummary) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Name, email, and issue summary are required.' },
|
||||
{ status: 400 },
|
||||
)
|
||||
}
|
||||
|
||||
await payload.create({
|
||||
collection: 'afterServiceRequests',
|
||||
data: {
|
||||
country: country || undefined,
|
||||
details: toRichText(details) || undefined,
|
||||
email,
|
||||
issueSummary,
|
||||
name,
|
||||
productModel: productModel || undefined,
|
||||
purchaseDate: purchaseDate || undefined,
|
||||
serialNumber: serialNumber || undefined,
|
||||
status: 'draft',
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Your support request has been submitted successfully.',
|
||||
ok: true,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Support contact submission failed', error)
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: 'Unable to submit the support request right now.' },
|
||||
{ status: 500 },
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user