chore: remove dead guest-register event route
The /api/events/[id]/guest-register endpoint has no production callers: it's superseded by tickets/purchase.post.js, which handles guest Member upsert via status:"guest" when body.createAccount is true. Drops the route file, its source-assertion tests, guestRegisterSchema, and its validation coverage.
This commit is contained in:
parent
5fb2f18cab
commit
3ba633cce2
4 changed files with 3 additions and 155 deletions
|
|
@ -1,104 +0,0 @@
|
|||
import Event from '../../../models/event.js'
|
||||
import { connectDB } from '../../../utils/mongoose.js'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
await connectDB()
|
||||
const identifier = getRouterParam(event, 'id')
|
||||
const body = await validateBody(event, guestRegisterSchema)
|
||||
|
||||
if (!identifier) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Event identifier is required'
|
||||
})
|
||||
}
|
||||
|
||||
// Fetch the event
|
||||
let eventData
|
||||
if (mongoose.Types.ObjectId.isValid(identifier)) {
|
||||
eventData = await Event.findById(identifier)
|
||||
}
|
||||
if (!eventData) {
|
||||
eventData = await Event.findOne({ slug: identifier })
|
||||
}
|
||||
|
||||
if (!eventData) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Event not found'
|
||||
})
|
||||
}
|
||||
|
||||
// Check if event allows public registration (not members-only)
|
||||
if (eventData.membersOnly) {
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: 'This event is for members only. Please become a member to register.'
|
||||
})
|
||||
}
|
||||
|
||||
// If event requires payment, reject guest registration
|
||||
if (eventData.pricing.paymentRequired && !eventData.pricing.isFree) {
|
||||
throw createError({
|
||||
statusCode: 402,
|
||||
statusMessage: 'This event requires payment. Please use the payment registration endpoint.'
|
||||
})
|
||||
}
|
||||
|
||||
// Check if event is full
|
||||
if (eventData.maxAttendees && eventData.registrations.length >= eventData.maxAttendees) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Event is full'
|
||||
})
|
||||
}
|
||||
|
||||
// Check if already registered
|
||||
const alreadyRegistered = eventData.registrations.some(
|
||||
reg => reg.email.toLowerCase() === body.email.toLowerCase()
|
||||
)
|
||||
|
||||
if (alreadyRegistered) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'You are already registered for this event'
|
||||
})
|
||||
}
|
||||
|
||||
// Add guest registration
|
||||
eventData.registrations.push({
|
||||
name: body.name,
|
||||
email: body.email.toLowerCase(),
|
||||
membershipLevel: 'guest',
|
||||
isMember: false,
|
||||
paymentStatus: 'not_required',
|
||||
amountPaid: 0,
|
||||
registeredAt: new Date()
|
||||
})
|
||||
|
||||
await eventData.save()
|
||||
|
||||
// TODO: Send confirmation email for guest registration
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Successfully registered as guest',
|
||||
registrationId: eventData.registrations[eventData.registrations.length - 1]._id,
|
||||
note: 'As a guest, you have access to this free public event. Consider becoming a member for access to all events!'
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error with guest registration:', error)
|
||||
|
||||
if (error.statusCode) {
|
||||
throw error
|
||||
}
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to register as guest'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
@ -125,11 +125,6 @@ export const checkRegistrationSchema = z.object({
|
|||
email: z.string().trim().toLowerCase().email()
|
||||
})
|
||||
|
||||
export const guestRegisterSchema = z.object({
|
||||
name: z.string().min(1).max(200),
|
||||
email: z.string().trim().toLowerCase().email()
|
||||
})
|
||||
|
||||
export const eventPaymentSchema = z.object({
|
||||
name: z.string().min(1).max(200),
|
||||
email: z.string().trim().toLowerCase().email(),
|
||||
|
|
|
|||
|
|
@ -41,32 +41,6 @@ describe('register.post.js', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('guest-register.post.js', () => {
|
||||
const source = readFileSync(resolve(eventsDir, 'guest-register.post.js'), 'utf-8')
|
||||
|
||||
it('uses validateBody for input validation', () => {
|
||||
expect(source).toContain('validateBody(event')
|
||||
})
|
||||
|
||||
it('checks membersOnly restriction with 403', () => {
|
||||
expect(source).toContain('membersOnly')
|
||||
expect(source).toContain('403')
|
||||
})
|
||||
|
||||
it('checks payment requirement with 402', () => {
|
||||
expect(source).toContain('paymentRequired')
|
||||
expect(source).toContain('402')
|
||||
})
|
||||
|
||||
it('checks capacity via maxAttendees', () => {
|
||||
expect(source).toContain('maxAttendees')
|
||||
})
|
||||
|
||||
it('does not require auth', () => {
|
||||
expect(source).not.toContain('requireAuth')
|
||||
})
|
||||
})
|
||||
|
||||
describe('cancel-registration.post.js', () => {
|
||||
const source = readFileSync(resolve(eventsDir, 'cancel-registration.post.js'), 'utf-8')
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import {
|
|||
waitlistDeleteSchema,
|
||||
cancelRegistrationSchema,
|
||||
checkRegistrationSchema,
|
||||
guestRegisterSchema,
|
||||
eventPaymentSchema,
|
||||
updateContributionSchema,
|
||||
seriesTicketPurchaseSchema,
|
||||
|
|
@ -25,6 +24,9 @@ import {
|
|||
adminMemberCreateSchema
|
||||
} from '../../../server/utils/schemas.js'
|
||||
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
// --- Helcim schemas ---
|
||||
|
||||
describe('helcimCreatePlanSchema', () => {
|
||||
|
|
@ -247,21 +249,6 @@ describe('waitlistSchema', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('guestRegisterSchema', () => {
|
||||
it('accepts valid guest data', () => {
|
||||
const result = guestRegisterSchema.safeParse({
|
||||
name: 'Guest User',
|
||||
email: 'guest@example.com'
|
||||
})
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects missing name', () => {
|
||||
const result = guestRegisterSchema.safeParse({ email: 'guest@example.com' })
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('eventPaymentSchema', () => {
|
||||
it('accepts valid payment data', () => {
|
||||
const result = eventPaymentSchema.safeParse({
|
||||
|
|
@ -459,9 +446,6 @@ describe('error text forwarding regression', () => {
|
|||
})
|
||||
})
|
||||
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
// --- validateBody migration coverage ---
|
||||
|
||||
describe('validateBody migration coverage', () => {
|
||||
|
|
@ -478,7 +462,6 @@ describe('validateBody migration coverage', () => {
|
|||
'events/[id]/waitlist.delete.js',
|
||||
'events/[id]/cancel-registration.post.js',
|
||||
'events/[id]/check-registration.post.js',
|
||||
'events/[id]/guest-register.post.js',
|
||||
'events/[id]/payment.post.js',
|
||||
'members/update-contribution.post.js',
|
||||
'series/[id]/tickets/purchase.post.js',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue