Initial release of Moniki paid services site and CMS (v1.0.0).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import type { CollectionConfig } from 'payload'
|
||||
import { ADMIN_GROUP } from '../admin/groups'
|
||||
|
||||
const BOOKING_HOLD_MS = 24 * 60 * 60 * 1000
|
||||
|
||||
export const Bookings: CollectionConfig = {
|
||||
slug: 'bookings',
|
||||
labels: { singular: 'Запись', plural: 'Записи' },
|
||||
admin: {
|
||||
group: ADMIN_GROUP.booking,
|
||||
useAsTitle: 'id',
|
||||
defaultColumns: ['patient', 'doctor', 'service', 'startsAt', 'status', 'paymentStatus'],
|
||||
},
|
||||
access: {
|
||||
create: ({ req: { user } }) => Boolean(user),
|
||||
read: ({ req: { user } }) => {
|
||||
if (!user) return false
|
||||
if (user.role === 'admin') return true
|
||||
return { patient: { equals: user.id } }
|
||||
},
|
||||
update: ({ req: { user } }) => {
|
||||
if (!user) return false
|
||||
if (user.role === 'admin') return true
|
||||
return { patient: { equals: user.id } }
|
||||
},
|
||||
delete: ({ req: { user } }) => user?.role === 'admin',
|
||||
},
|
||||
hooks: {
|
||||
beforeChange: [
|
||||
async ({ data, operation, originalDoc }) => {
|
||||
if (operation === 'create') {
|
||||
data.status = data.status || 'pending'
|
||||
data.holdExpiresAt = new Date(Date.now() + BOOKING_HOLD_MS).toISOString()
|
||||
data.paymentStatus = data.paymentStatus || 'unpaid'
|
||||
}
|
||||
|
||||
// Patient cancel / reschedule
|
||||
if (operation === 'update' && data.status === 'cancelled' && originalDoc?.status !== 'cancelled') {
|
||||
data.cancelledAt = new Date().toISOString()
|
||||
}
|
||||
|
||||
return data
|
||||
},
|
||||
],
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'patient',
|
||||
type: 'relationship',
|
||||
relationTo: 'users',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'doctor',
|
||||
type: 'relationship',
|
||||
relationTo: 'doctors',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'service',
|
||||
type: 'relationship',
|
||||
relationTo: 'services',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'branch',
|
||||
type: 'relationship',
|
||||
relationTo: 'branches',
|
||||
required: true,
|
||||
},
|
||||
{ name: 'startsAt', type: 'date', required: true, admin: { date: { pickerAppearance: 'dayAndTime' } } },
|
||||
{ name: 'endsAt', type: 'date', required: true, admin: { date: { pickerAppearance: 'dayAndTime' } } },
|
||||
{
|
||||
name: 'status',
|
||||
type: 'select',
|
||||
required: true,
|
||||
defaultValue: 'pending',
|
||||
options: [
|
||||
{ label: 'Ожидает подтверждения (бронь до 24ч)', value: 'pending' },
|
||||
{ label: 'Подтверждена', value: 'confirmed' },
|
||||
{ label: 'Отменена', value: 'cancelled' },
|
||||
{ label: 'Завершена', value: 'completed' },
|
||||
{ label: 'Истекла (не подтверждена)', value: 'expired' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'paymentStatus',
|
||||
type: 'select',
|
||||
defaultValue: 'unpaid',
|
||||
options: [
|
||||
{ label: 'Не оплачено', value: 'unpaid' },
|
||||
{ label: 'Ожидает оплаты', value: 'pending' },
|
||||
{ label: 'Оплачено', value: 'paid' },
|
||||
{ label: 'Ошибка оплаты', value: 'failed' },
|
||||
{ label: 'Возврат', value: 'refunded' },
|
||||
],
|
||||
},
|
||||
{ name: 'price', type: 'number', required: true },
|
||||
{ name: 'holdExpiresAt', type: 'date', admin: { readOnly: true } },
|
||||
{ name: 'confirmedAt', type: 'date' },
|
||||
{ name: 'cancelledAt', type: 'date' },
|
||||
{ name: 'cancelReason', type: 'text' },
|
||||
{ name: 'rescheduledFrom', type: 'relationship', relationTo: 'bookings' },
|
||||
{ name: 'patientComment', type: 'textarea' },
|
||||
{
|
||||
name: 'smsReminderScheduled',
|
||||
type: 'checkbox',
|
||||
defaultValue: false,
|
||||
admin: { description: 'Флаг для будущей SMS-рассылки напоминаний' },
|
||||
},
|
||||
],
|
||||
timestamps: true,
|
||||
}
|
||||
Reference in New Issue
Block a user