feat: add clinic management and financial reporting features
- Implemented ClinicFormPage for adding new clinics with validation. - Created MyFinancialPage to display financial summaries and charts. - Developed MyPatientsPage for managing patient data with search and pagination. - Added PreRegistrationsPage for handling pre-registration requests with approval and rejection functionalities. - Introduced database migration for pre_registrations table. - Built PreRegistrationController for managing pre-registration logic, including submission, approval, and rejection. - Created PreRegistration entity and repository for handling pre-registration data.
This commit is contained in:
@@ -29,6 +29,10 @@ import SecretariesPage from './pages/SecretariesPage';
|
||||
import MyClinicPage from './pages/MyClinicPage';
|
||||
import SettingsPage from './pages/SettingsPage';
|
||||
import DoctorProfilePage from './pages/DoctorProfilePage';
|
||||
import MyPatientsPage from './pages/MyPatientsPage';
|
||||
import MyFinancialPage from './pages/MyFinancialPage';
|
||||
import ClinicFormPage from './pages/ClinicFormPage';
|
||||
import PreRegistrationsPage from './pages/PreRegistrationsPage';
|
||||
|
||||
// ── Guards ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -134,6 +138,14 @@ export default function App() {
|
||||
<Route path="doctors/new" element={<RoleRoute roles={['admin']}><DoctorFormPage /></RoleRoute>} />
|
||||
<Route path="doctors/:uuid" element={<RoleRoute roles={['admin', 'doctor']}><DoctorDetailPage /></RoleRoute>} />
|
||||
<Route path="profile" element={<RoleRoute roles={['doctor']}><DoctorProfilePage /></RoleRoute>} />
|
||||
|
||||
{/* دکتر / منشی / کلینیک */}
|
||||
<Route path="my-patients" element={<RoleRoute roles={['doctor', 'secretary', 'clinic']}><MyPatientsPage /></RoleRoute>} />
|
||||
<Route path="my-financial" element={<RoleRoute roles={['doctor', 'secretary', 'clinic']}><MyFinancialPage /></RoleRoute>} />
|
||||
|
||||
{/* فقط ادمین */}
|
||||
<Route path="clinics/new" element={<RoleRoute roles={['admin']}><ClinicFormPage /></RoleRoute>} />
|
||||
<Route path="pre-registrations" element={<RoleRoute roles={['admin']}><PreRegistrationsPage /></RoleRoute>} />
|
||||
</Route>
|
||||
|
||||
<Route path="*" element={<Navigate to="/admin/dashboard" replace />} />
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
ArrowsRightLeftIcon,
|
||||
BanknotesIcon,
|
||||
BuildingOffice2Icon,
|
||||
ClipboardDocumentCheckIcon,
|
||||
Cog6ToothIcon,
|
||||
CalendarDaysIcon,
|
||||
ChartBarIcon,
|
||||
@@ -43,6 +44,7 @@ function buildSections(primaryRole: string | null, dbUuid: string | null): Secti
|
||||
{ to: '/admin/appointments', icon: CalendarDaysIcon, label: 'نوبتها' },
|
||||
{ to: '/admin/payments', icon: CreditCardIcon, label: 'پرداختها' },
|
||||
{ to: '/admin/settlements', icon: BanknotesIcon, label: 'تسویهحساب' },
|
||||
{ to: '/admin/pre-registrations', icon: ClipboardDocumentCheckIcon, label: 'درخواستهای ثبتنام' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { ArrowRightIcon, BuildingOffice2Icon } from '@heroicons/react/24/outline';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import type { ApiResponse } from '../lib/api';
|
||||
|
||||
const schema = z.object({
|
||||
owner_mobile: z.string().min(10, 'شماره موبایل معتبر نیست').max(15),
|
||||
name: z.string().min(2, 'نام کلینیک حداقل ۲ کاراکتر'),
|
||||
telephone: z.string().max(20).optional().or(z.literal('')),
|
||||
address: z.string().max(500).optional().or(z.literal('')),
|
||||
info: z.string().max(2000).optional().or(z.literal('')),
|
||||
});
|
||||
type FormValues = z.infer<typeof schema>;
|
||||
|
||||
interface ClinicCreated { uuid: string; name: string; is_active: boolean }
|
||||
|
||||
export default function ClinicFormPage() {
|
||||
const navigate = useNavigate();
|
||||
const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm<FormValues>({ resolver: zodResolver(schema) });
|
||||
|
||||
const mutation = useMutation<ApiResponse<ClinicCreated>, Error, FormValues>({
|
||||
mutationFn: (body) => api.post('/api/v1/admin/clinic', body),
|
||||
onSuccess: (res) => {
|
||||
toast.success(`کلینیک "${res?.data?.name}" ایجاد شد`);
|
||||
navigate('/admin/clinics');
|
||||
},
|
||||
onError: (err) => toast.error(err.message ?? 'خطا در ایجاد کلینیک'),
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="page" style={{ maxWidth: 640 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 28 }}>
|
||||
<button className="btn ghost sm" onClick={() => navigate('/admin/clinics')}>
|
||||
<ArrowRightIcon style={{ width: 16, height: 16 }} />بازگشت
|
||||
</button>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<BuildingOffice2Icon style={{ width: 22, height: 22, color: 'var(--primary)' }} />
|
||||
<h1 style={{ margin: 0, fontSize: 20, fontWeight: 700 }}>افزودن کلینیک جدید</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<form onSubmit={handleSubmit((v) => mutation.mutate(v))} style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
<label style={{ fontSize: 13, fontWeight: 600 }}>شماره موبایل صاحب کلینیک <span style={{ color: 'var(--red)' }}>*</span></label>
|
||||
<input className="field" placeholder="09xxxxxxxxx" dir="ltr" {...register('owner_mobile')} />
|
||||
{errors.owner_mobile && <span style={{ color: 'var(--red)', fontSize: 12 }}>{errors.owner_mobile.message}</span>}
|
||||
<span style={{ fontSize: 11, color: 'var(--text-3)' }}>اگر این موبایل در سیستم نباشد، کاربر جدید ساخته میشود</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
<label style={{ fontSize: 13, fontWeight: 600 }}>نام کلینیک <span style={{ color: 'var(--red)' }}>*</span></label>
|
||||
<input className="field" placeholder="مثال: کلینیک تخصصی پارسیان" {...register('name')} />
|
||||
{errors.name && <span style={{ color: 'var(--red)', fontSize: 12 }}>{errors.name.message}</span>}
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
<label style={{ fontSize: 13, fontWeight: 600 }}>تلفن ثابت</label>
|
||||
<input className="field" placeholder="02xxxxxxxx" dir="ltr" {...register('telephone')} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
<label style={{ fontSize: 13, fontWeight: 600 }}>آدرس</label>
|
||||
<input className="field" placeholder="آدرس کلینیک" {...register('address')} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
<label style={{ fontSize: 13, fontWeight: 600 }}>توضیحات</label>
|
||||
<textarea className="field" rows={3} placeholder="درباره کلینیک..." {...register('info')} style={{ resize: 'vertical' }} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 12, justifyContent: 'flex-end', paddingTop: 8 }}>
|
||||
<button type="button" className="btn ghost" onClick={() => navigate('/admin/clinics')}>انصراف</button>
|
||||
<button type="submit" className="btn primary" disabled={isSubmitting || mutation.isPending}>
|
||||
{mutation.isPending ? 'در حال ذخیره...' : 'ایجاد کلینیک'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import React from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../lib/api';
|
||||
import type { ApiResponse } from '../lib/api';
|
||||
import { formatRial } from '../lib/utils';
|
||||
import PageHeader from '../components/ui/PageHeader';
|
||||
|
||||
interface MonthlyEntry {
|
||||
month: string;
|
||||
paid: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface FinancialSummary {
|
||||
total_paid: number;
|
||||
total_pending: number;
|
||||
total_refunded: number;
|
||||
count_paid: number;
|
||||
monthly_chart: MonthlyEntry[];
|
||||
}
|
||||
|
||||
function KpiCard({ label, value, color }: { label: string; value: string; color: string }) {
|
||||
return (
|
||||
<div className="card" style={{ flex: '1 1 200px', minWidth: 0 }}>
|
||||
<div style={{ color: 'var(--text-3)', fontSize: 13, marginBottom: 6 }}>{label}</div>
|
||||
<div style={{ fontSize: 22, fontWeight: 700, color }}>{value}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const BAR_MAX_HEIGHT = 120;
|
||||
|
||||
export default function MyFinancialPage() {
|
||||
const { data, isLoading } = useQuery<ApiResponse<FinancialSummary>>({
|
||||
queryKey: ['my-financial-summary'],
|
||||
queryFn: () => api.get('/api/v1/my/financial-summary'),
|
||||
});
|
||||
|
||||
const summary = data?.data;
|
||||
const maxPaid = summary?.monthly_chart?.reduce((m, e) => Math.max(m, e.paid), 1) ?? 1;
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
<PageHeader title="گزارش مالی" description="خلاصه پرداختهای بیماران" />
|
||||
|
||||
{isLoading ? (
|
||||
<div style={{ padding: 40, textAlign: 'center', color: 'var(--text-3)' }}>در حال بارگذاری...</div>
|
||||
) : (
|
||||
<>
|
||||
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap', marginBottom: 24 }}>
|
||||
<KpiCard label="مجموع پرداخت شده" value={formatRial(summary?.total_paid ?? 0)} color="var(--green)" />
|
||||
<KpiCard label="در انتظار پرداخت" value={formatRial(summary?.total_pending ?? 0)} color="var(--orange)" />
|
||||
<KpiCard label="مجموع استرداد" value={formatRial(summary?.total_refunded ?? 0)} color="var(--red)" />
|
||||
<KpiCard label="تعداد پرداخت موفق" value={String(summary?.count_paid ?? 0)} color="var(--primary)" />
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div style={{ fontWeight: 600, marginBottom: 20 }}>نمودار ۶ ماه اخیر</div>
|
||||
{summary?.monthly_chart?.length ? (
|
||||
<div style={{ display: 'flex', alignItems: 'flex-end', gap: 12, height: BAR_MAX_HEIGHT + 40 }}>
|
||||
{summary.monthly_chart.map((entry) => {
|
||||
const barH = Math.max(4, Math.round((entry.paid / maxPaid) * BAR_MAX_HEIGHT));
|
||||
return (
|
||||
<div key={entry.month} style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 6 }}>
|
||||
<div style={{ fontSize: 11, color: 'var(--text-3)' }}>{formatRial(entry.paid)}</div>
|
||||
<div
|
||||
style={{ width: '100%', height: barH, borderRadius: 6, background: 'linear-gradient(to top, var(--primary), oklch(0.72 0.16 256))', transition: 'height 0.3s ease' }}
|
||||
title={`${entry.month}: ${formatRial(entry.paid)} — ${entry.count} پرداخت`}
|
||||
/>
|
||||
<div style={{ fontSize: 11, color: 'var(--text-2)', whiteSpace: 'nowrap' }}>{entry.month}</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', color: 'var(--text-3)', padding: 32 }}>دادهای برای نمایش وجود ندارد</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { PhoneIcon } from '@heroicons/react/24/outline';
|
||||
import { api } from '../lib/api';
|
||||
import type { PaginatedResponse } from '../lib/api';
|
||||
import { formatDate, formatNumber } from '../lib/utils';
|
||||
import DataTable, { type Column } from '../components/ui/DataTable';
|
||||
import Pagination from '../components/ui/Pagination';
|
||||
import PageHeader from '../components/ui/PageHeader';
|
||||
|
||||
interface Patient {
|
||||
uuid: string;
|
||||
name: string;
|
||||
mobile: string;
|
||||
total_appointments: number;
|
||||
last_appointment: number | null;
|
||||
}
|
||||
|
||||
const EMPTY: Patient[] = [];
|
||||
|
||||
export default function MyPatientsPage() {
|
||||
const [page, setPage] = useState(1);
|
||||
const [search, setSearch] = useState('');
|
||||
const limit = 20;
|
||||
|
||||
const { data, isLoading } = useQuery<PaginatedResponse<Patient>>({
|
||||
queryKey: ['my-patients', page, search],
|
||||
queryFn: () => api.get(`/api/v1/my/patients?page=${page}&limit=${limit}&search=${encodeURIComponent(search)}`),
|
||||
});
|
||||
|
||||
const patients = data?.data ?? EMPTY;
|
||||
const total = data?.meta?.totalRecords ?? 0;
|
||||
|
||||
const columns: Column<Patient>[] = [
|
||||
{
|
||||
key: 'name',
|
||||
header: 'نام بیمار',
|
||||
render: (p) => (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<div className="avatar sm" style={{ background: 'linear-gradient(145deg, oklch(0.62 0.15 256), oklch(0.48 0.16 256))', flexShrink: 0 }}>
|
||||
{(p.name || '؟').charAt(0)}
|
||||
</div>
|
||||
<span>{p.name || '—'}</span>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'mobile',
|
||||
header: 'موبایل',
|
||||
render: (p) => (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, direction: 'ltr' }}>
|
||||
<PhoneIcon style={{ width: 14, height: 14, color: 'var(--text-3)' }} />
|
||||
<span>{p.mobile}</span>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'total_appointments',
|
||||
header: 'تعداد نوبت',
|
||||
render: (p) => <span className="badge blue">{formatNumber(p.total_appointments)}</span>,
|
||||
},
|
||||
{
|
||||
key: 'last_appointment',
|
||||
header: 'آخرین نوبت',
|
||||
render: (p) => p.last_appointment ? formatDate(String(p.last_appointment)) : '—',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
<PageHeader title="بیماران من" description={`${formatNumber(total)} بیمار`} />
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={patients}
|
||||
loading={isLoading}
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1); }}
|
||||
searchPlaceholder="جستجوی نام یا موبایل..."
|
||||
emptyMessage="بیماری یافت نشد"
|
||||
/>
|
||||
|
||||
<Pagination page={page} total={total} limit={limit} onPageChange={setPage} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { CheckIcon, XMarkIcon, PhoneIcon } from '@heroicons/react/24/outline';
|
||||
import { toast } from 'sonner';
|
||||
import { api } from '../lib/api';
|
||||
import type { PaginatedResponse } from '../lib/api';
|
||||
import { formatDate } from '../lib/utils';
|
||||
import PageHeader from '../components/ui/PageHeader';
|
||||
import Pagination from '../components/ui/Pagination';
|
||||
import ConfirmDialog from '../components/ui/ConfirmDialog';
|
||||
|
||||
interface PreRegistration {
|
||||
uuid: string;
|
||||
type: 'independent_doctor' | 'doctor_with_clinic' | 'clinic_manager';
|
||||
name: string;
|
||||
mobile: string;
|
||||
info: string | null;
|
||||
status: 'pending' | 'approved' | 'rejected';
|
||||
admin_note: string | null;
|
||||
created_at: number;
|
||||
}
|
||||
|
||||
const EMPTY: PreRegistration[] = [];
|
||||
|
||||
const TYPE_META: Record<string, { label: string; color: string }> = {
|
||||
independent_doctor: { label: 'دکتر', color: 'blue' },
|
||||
doctor_with_clinic: { label: 'دکتر + کلینیک', color: 'purple' },
|
||||
clinic_manager: { label: 'مدیر کلینیک', color: 'orange' },
|
||||
};
|
||||
|
||||
const STATUS_META: Record<string, { label: string; color: string }> = {
|
||||
pending: { label: 'در انتظار', color: 'yellow' },
|
||||
approved: { label: 'تأیید شده', color: 'green' },
|
||||
rejected: { label: 'رد شده', color: 'red' },
|
||||
};
|
||||
|
||||
const STATUS_TABS = [
|
||||
{ value: 'pending', label: 'در انتظار' },
|
||||
{ value: 'approved', label: 'تأیید شده' },
|
||||
{ value: 'rejected', label: 'رد شده' },
|
||||
{ value: 'all', label: 'همه' },
|
||||
];
|
||||
|
||||
export default function PreRegistrationsPage() {
|
||||
const qc = useQueryClient();
|
||||
const [page, setPage] = useState(1);
|
||||
const [statusFilter, setStatusFilter] = useState('pending');
|
||||
const [approveTarget, setApproveTarget] = useState<PreRegistration | null>(null);
|
||||
const [rejectTarget, setRejectTarget] = useState<PreRegistration | null>(null);
|
||||
const [rejectNote, setRejectNote] = useState('');
|
||||
const limit = 20;
|
||||
|
||||
const { data, isLoading } = useQuery<PaginatedResponse<PreRegistration>>({
|
||||
queryKey: ['pre-registrations', page, statusFilter],
|
||||
queryFn: () => api.get(`/api/v1/admin/pre-registrations?page=${page}&limit=${limit}&status=${statusFilter}`),
|
||||
});
|
||||
|
||||
const items = data?.data ?? EMPTY;
|
||||
const total = data?.meta?.totalRecords ?? 0;
|
||||
|
||||
const approveMutation = useMutation({
|
||||
mutationFn: (uuid: string) => api.post(`/api/v1/admin/pre-registrations/${uuid}/approve`, {}),
|
||||
onSuccess: () => {
|
||||
toast.success('درخواست تأیید شد و اطلاعات ورود ارسال گردید');
|
||||
setApproveTarget(null);
|
||||
qc.invalidateQueries({ queryKey: ['pre-registrations'] });
|
||||
},
|
||||
onError: (err: Error) => toast.error(err.message),
|
||||
});
|
||||
|
||||
const rejectMutation = useMutation({
|
||||
mutationFn: ({ uuid, note }: { uuid: string; note: string }) =>
|
||||
api.post(`/api/v1/admin/pre-registrations/${uuid}/reject`, { note: note || undefined }),
|
||||
onSuccess: () => {
|
||||
toast.success('درخواست رد شد');
|
||||
setRejectTarget(null);
|
||||
setRejectNote('');
|
||||
qc.invalidateQueries({ queryKey: ['pre-registrations'] });
|
||||
},
|
||||
onError: (err: Error) => toast.error(err.message),
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
<PageHeader title="درخواستهای ثبتنام" description={`${total} درخواست`} />
|
||||
|
||||
{/* Tabs */}
|
||||
<div className="seg" style={{ marginBottom: 20, width: 'fit-content' }}>
|
||||
{STATUS_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.value}
|
||||
className={statusFilter === tab.value ? 'active' : ''}
|
||||
onClick={() => { setStatusFilter(tab.value); setPage(1); }}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="card" style={{ padding: 0, overflow: 'hidden' }}>
|
||||
<table className="t">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>نام</th>
|
||||
<th>موبایل</th>
|
||||
<th>نوع حساب</th>
|
||||
<th>توضیحات</th>
|
||||
<th>وضعیت</th>
|
||||
<th>تاریخ درخواست</th>
|
||||
{statusFilter === 'pending' && <th />}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{isLoading
|
||||
? Array.from({ length: 8 }).map((_, i) => (
|
||||
<tr key={i}>
|
||||
{Array.from({ length: 6 }).map((_, j) => (
|
||||
<td key={j}><div className="skeleton" style={{ height: 16, borderRadius: 6 }} /></td>
|
||||
))}
|
||||
</tr>
|
||||
))
|
||||
: items.length === 0
|
||||
? (
|
||||
<tr>
|
||||
<td colSpan={7} style={{ textAlign: 'center', padding: 48, color: 'var(--text-3)' }}>
|
||||
درخواستی یافت نشد
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
: items.map((item) => {
|
||||
const typeMeta = TYPE_META[item.type] ?? { label: item.type, color: 'gray' };
|
||||
const statusMeta = STATUS_META[item.status] ?? { label: item.status, color: 'gray' };
|
||||
return (
|
||||
<tr key={item.uuid}>
|
||||
<td>
|
||||
<div style={{ fontWeight: 600 }}>{item.name}</div>
|
||||
</td>
|
||||
<td>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, direction: 'ltr' }}>
|
||||
<PhoneIcon style={{ width: 13, height: 13, color: 'var(--text-3)' }} />
|
||||
<span style={{ fontSize: 13 }}>{item.mobile}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span className={`badge ${typeMeta.color}`}>
|
||||
<span className="bdot" />{typeMeta.label}
|
||||
</span>
|
||||
</td>
|
||||
<td style={{ maxWidth: 200 }}>
|
||||
<span style={{ fontSize: 12, color: 'var(--text-2)', display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical', overflow: 'hidden' }}>
|
||||
{item.info || '—'}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span className={`badge ${statusMeta.color}`}>
|
||||
<span className="bdot" />{statusMeta.label}
|
||||
</span>
|
||||
{item.admin_note && (
|
||||
<div style={{ fontSize: 11, color: 'var(--text-3)', marginTop: 3 }}>{item.admin_note}</div>
|
||||
)}
|
||||
</td>
|
||||
<td style={{ fontSize: 13 }}>{formatDate(String(item.created_at))}</td>
|
||||
{statusFilter === 'pending' && (
|
||||
<td>
|
||||
<div className="row-actions">
|
||||
<button
|
||||
className="mini-btn"
|
||||
title="تأیید"
|
||||
style={{ color: 'var(--green)' }}
|
||||
onClick={() => setApproveTarget(item)}
|
||||
>
|
||||
<CheckIcon style={{ width: 16, height: 16 }} />
|
||||
</button>
|
||||
<button
|
||||
className="mini-btn"
|
||||
title="رد"
|
||||
style={{ color: 'var(--red)' }}
|
||||
onClick={() => { setRejectTarget(item); setRejectNote(''); }}
|
||||
>
|
||||
<XMarkIcon style={{ width: 16, height: 16 }} />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<Pagination page={page} total={total} limit={limit} onPageChange={setPage} />
|
||||
|
||||
{/* Approve Dialog */}
|
||||
<ConfirmDialog
|
||||
open={!!approveTarget}
|
||||
title="تأیید درخواست"
|
||||
message={`آیا درخواست "${approveTarget?.name}" را تأیید میکنید؟ اطلاعات ورود از طریق SMS ارسال خواهد شد.`}
|
||||
confirmLabel="تأیید و ارسال SMS"
|
||||
loading={approveMutation.isPending}
|
||||
onConfirm={() => approveTarget && approveMutation.mutate(approveTarget.uuid)}
|
||||
onCancel={() => setApproveTarget(null)}
|
||||
/>
|
||||
|
||||
{/* Reject Dialog */}
|
||||
{rejectTarget && (
|
||||
<div className="overlay" onClick={() => setRejectTarget(null)}>
|
||||
<div className="modal" style={{ maxWidth: 420 }} onClick={(e) => e.stopPropagation()}>
|
||||
<div className="modal-head">
|
||||
<b>رد درخواست — {rejectTarget.name}</b>
|
||||
</div>
|
||||
<div className="modal-body" style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
<p style={{ margin: 0, fontSize: 13, color: 'var(--text-2)' }}>در صورت تمایل دلیل رد را وارد کنید (اختیاری)</p>
|
||||
<textarea
|
||||
className="field"
|
||||
rows={3}
|
||||
placeholder="دلیل رد..."
|
||||
value={rejectNote}
|
||||
onChange={(e) => setRejectNote(e.target.value)}
|
||||
style={{ resize: 'vertical' }}
|
||||
/>
|
||||
</div>
|
||||
<div className="modal-foot">
|
||||
<button className="btn ghost sm" onClick={() => setRejectTarget(null)}>انصراف</button>
|
||||
<button
|
||||
className="btn danger sm"
|
||||
disabled={rejectMutation.isPending}
|
||||
onClick={() => rejectMutation.mutate({ uuid: rejectTarget.uuid, note: rejectNote })}
|
||||
>
|
||||
{rejectMutation.isPending ? 'در حال رد...' : 'رد درخواست'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ security:
|
||||
provider: api_doc_provider
|
||||
|
||||
public_endpoints:
|
||||
pattern: ^/(api/v1/user/(send-code|verify-code|register)|oauth/token$|session/token|api/v1/categorys/|api/v1/doctors$|api/v1/clinics$|api/v1/clinic/doctor-list/|api/v1/clinic-pro/doctor-addresses/|api/v1/appointment-slots|api/v1/comments/|api/v1/rate/|api/v1/blogs$|api/v1/clinic-invitation/)
|
||||
pattern: ^/(api/v1/user/(send-code|verify-code|register)|oauth/token$|session/token|api/v1/categorys/|api/v1/doctors$|api/v1/clinics$|api/v1/clinic/doctor-list/|api/v1/clinic-pro/doctor-addresses/|api/v1/appointment-slots|api/v1/comments/|api/v1/rate/|api/v1/blogs$|api/v1/clinic-invitation/|api/v1/pre-registration$)
|
||||
stateless: true
|
||||
security: false
|
||||
|
||||
|
||||
@@ -801,3 +801,73 @@ Update one or more settings. Unknown keys are silently ignored.
|
||||
- `commission_enabled` — `"1"` = active, `"0"` = inactive
|
||||
- `commission_percent` — integer string, `0`–`100`
|
||||
- Commission applies only to regular users (`booked_by = user`); secretaries are exempt
|
||||
|
||||
---
|
||||
|
||||
## Pre-Registration Management
|
||||
|
||||
### GET `/api/v1/admin/pre-registrations`
|
||||
|
||||
List pre-registration requests. **Permission:** `ROLE_ADMIN`
|
||||
|
||||
**Query params:**
|
||||
|
||||
| Param | Default | Notes |
|
||||
|-------|---------|-------|
|
||||
| `page` | 1 | |
|
||||
| `limit` | 20 | max 50 |
|
||||
| `status` | `pending` | `pending` \| `approved` \| `rejected` \| `all` |
|
||||
|
||||
**Response `200`** (paginated):
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"uuid": "...",
|
||||
"type": "independent_doctor",
|
||||
"name": "دکتر احمدی",
|
||||
"mobile": "09121234567",
|
||||
"info": "متخصص داخلی",
|
||||
"status": "pending",
|
||||
"admin_note": null,
|
||||
"created_at": 1718000000
|
||||
}
|
||||
],
|
||||
"meta": { "totalRecords": 5, "totalPages": 1, "currentPage": 1 }
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### POST `/api/v1/admin/pre-registrations/{uuid}/approve`
|
||||
|
||||
Approve a pending request. Creates User + Doctor/Clinic entity based on `type`, resets password, sends SMS. **Permission:** `ROLE_ADMIN`
|
||||
|
||||
**Response `200`:**
|
||||
```json
|
||||
{ "success": true, "data": { "message": "تأیید شد و اطلاعات ورود ارسال گردید" } }
|
||||
```
|
||||
|
||||
**Error Codes:**
|
||||
|
||||
| Code | HTTP | Meaning |
|
||||
|------|------|---------|
|
||||
| `NOT_FOUND` | 404 | UUID not found |
|
||||
| `ALREADY_PROCESSED` | 409 | Status is not pending |
|
||||
|
||||
---
|
||||
|
||||
### POST `/api/v1/admin/pre-registrations/{uuid}/reject`
|
||||
|
||||
Reject a pending request. **Permission:** `ROLE_ADMIN`
|
||||
|
||||
**Request body** (optional):
|
||||
```json
|
||||
{ "note": "مدارک ناقص است" }
|
||||
```
|
||||
|
||||
**Response `200`:**
|
||||
```json
|
||||
{ "success": true, "data": { "message": "درخواست رد شد" } }
|
||||
```
|
||||
|
||||
@@ -507,3 +507,50 @@ Invalidate the refresh token (stored in Redis).
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## POST `/api/v1/pre-registration`
|
||||
|
||||
Submit a pre-registration request (doctor or clinic). Public endpoint — no auth required.
|
||||
|
||||
**Permission:** Public
|
||||
|
||||
### Request Body
|
||||
```json
|
||||
{
|
||||
"type": "independent_doctor",
|
||||
"name": "دکتر علی احمدی",
|
||||
"mobile": "09121234567",
|
||||
"info": "متخصص داخلی، ۱۰ سال سابقه"
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Required | Notes |
|
||||
|-------|------|----------|-------|
|
||||
| `type` | string | ✅ | `independent_doctor` \| `doctor_with_clinic` \| `clinic_manager` |
|
||||
| `name` | string | ✅ | min 2 chars |
|
||||
| `mobile` | string | ✅ | 10–15 chars |
|
||||
| `info` | string | ❌ | specialty, address, etc. |
|
||||
|
||||
**Type meanings:**
|
||||
|
||||
| Value | Roles granted on approval | Entities created |
|
||||
|-------|--------------------------|-----------------|
|
||||
| `independent_doctor` | `ROLE_DOCTOR` | Doctor |
|
||||
| `doctor_with_clinic` | `ROLE_DOCTOR` + `ROLE_CLINIC` | Doctor + Clinic |
|
||||
| `clinic_manager` | `ROLE_CLINIC` | Clinic |
|
||||
|
||||
### Response `200`
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"data": { "uuid": "...", "status": "pending" }
|
||||
}
|
||||
```
|
||||
|
||||
### Error Codes
|
||||
| Code | HTTP | Meaning |
|
||||
|------|------|---------|
|
||||
| `VALIDATION_ERROR` | 422 | Invalid type / mobile / name |
|
||||
| `DUPLICATE_REQUEST` | 409 | Pending request already exists for this mobile |
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260612081739 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE pre_registrations (id INT AUTO_INCREMENT NOT NULL, uuid VARCHAR(36) NOT NULL, type VARCHAR(30) NOT NULL, name VARCHAR(255) NOT NULL, mobile VARCHAR(20) NOT NULL, info LONGTEXT DEFAULT NULL, status VARCHAR(20) NOT NULL, admin_note LONGTEXT DEFAULT NULL, created_at INT NOT NULL, updated_at INT NOT NULL, UNIQUE INDEX UNIQ_A9113AD2D17F50A6 (uuid), INDEX idx_prereg_mobile (mobile), INDEX idx_prereg_status (status), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP TABLE pre_registrations');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace App\Auth\Controller;
|
||||
|
||||
use App\Auth\Entity\PreRegistration;
|
||||
use App\Auth\Entity\User;
|
||||
use App\Auth\Repository\PreRegistrationRepository;
|
||||
use App\Auth\Repository\UserRepository;
|
||||
use App\Clinic\Entity\Clinic;
|
||||
use App\Clinic\Repository\ClinicRepository;
|
||||
use App\Doctor\Entity\Doctor;
|
||||
use App\Doctor\Repository\DoctorRepository;
|
||||
use App\Shared\Constant\ErrorCodes;
|
||||
use App\Shared\Controller\BaseController;
|
||||
use App\Sms\Service\SmsService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class PreRegistrationController extends BaseController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly PreRegistrationRepository $preRegRepo,
|
||||
private readonly UserRepository $userRepo,
|
||||
private readonly DoctorRepository $doctorRepo,
|
||||
private readonly ClinicRepository $clinicRepo,
|
||||
private readonly UserPasswordHasherInterface $hasher,
|
||||
private readonly SmsService $sms,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {}
|
||||
|
||||
#[Route('/api/v1/pre-registration', methods: ['POST'])]
|
||||
public function submit(Request $request): JsonResponse
|
||||
{
|
||||
$data = json_decode($request->getContent(), true) ?? [];
|
||||
$type = trim($data['type'] ?? '');
|
||||
$name = trim($data['name'] ?? '');
|
||||
$mobile = trim($data['mobile'] ?? '');
|
||||
$info = trim($data['info'] ?? '') ?: null;
|
||||
|
||||
$validTypes = [
|
||||
PreRegistration::TYPE_INDEPENDENT_DOCTOR,
|
||||
PreRegistration::TYPE_DOCTOR_WITH_CLINIC,
|
||||
PreRegistration::TYPE_CLINIC_MANAGER,
|
||||
];
|
||||
|
||||
if (!in_array($type, $validTypes, true)) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'نوع حساب معتبر نیست', 422);
|
||||
}
|
||||
if (mb_strlen($mobile) < 10 || mb_strlen($mobile) > 15) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'شماره موبایل معتبر نیست', 422);
|
||||
}
|
||||
if (mb_strlen($name) < 2) {
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_001, 'نام الزامی است', 422);
|
||||
}
|
||||
|
||||
if ($this->preRegRepo->hasPendingForMobile($mobile)) {
|
||||
return $this->error('DUPLICATE_REQUEST', 'درخواست ثبتنام شما در حال بررسی است', 409);
|
||||
}
|
||||
|
||||
$preReg = new PreRegistration($type, $name, $mobile, $info);
|
||||
$this->em->persist($preReg);
|
||||
$this->em->flush();
|
||||
|
||||
return $this->success(['uuid' => $preReg->getUuid(), 'status' => $preReg->getStatus()]);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/admin/pre-registrations', methods: ['GET'])]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function list(Request $request): JsonResponse
|
||||
{
|
||||
$page = max(1, (int) $request->query->get('page', 1));
|
||||
$limit = min(50, max(1, (int) $request->query->get('limit', 20)));
|
||||
$status = $request->query->get('status', 'pending');
|
||||
|
||||
$qb = $this->em->createQueryBuilder()
|
||||
->select('p.uuid, p.type, p.name, p.mobile, p.info, p.status, p.adminNote AS admin_note, p.createdAt AS created_at')
|
||||
->from(PreRegistration::class, 'p');
|
||||
|
||||
if ($status !== 'all') {
|
||||
$qb->where('p.status = :status')->setParameter('status', $status);
|
||||
}
|
||||
|
||||
$total = (clone $qb)->select('COUNT(p.id)')->getQuery()->getSingleScalarResult();
|
||||
|
||||
$items = $qb
|
||||
->orderBy('p.createdAt', 'DESC')
|
||||
->setFirstResult(($page - 1) * $limit)
|
||||
->setMaxResults($limit)
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
|
||||
return $this->paginated($items, (int) $total, $page, $limit);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/admin/pre-registrations/{uuid}/approve', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function approve(string $uuid): JsonResponse
|
||||
{
|
||||
$preReg = $this->preRegRepo->findOneBy(['uuid' => $uuid]);
|
||||
if (!$preReg) {
|
||||
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'درخواست یافت نشد', 404);
|
||||
}
|
||||
if (!$preReg->isPending()) {
|
||||
return $this->error(ErrorCodes::ERR_CONFLICT_001, 'این درخواست قبلاً پردازش شده است', 409);
|
||||
}
|
||||
|
||||
$password = bin2hex(random_bytes(4));
|
||||
|
||||
$user = $this->userRepo->findOneBy(['mobileNumber' => $preReg->getMobile()]);
|
||||
if (!$user) {
|
||||
$user = new User($preReg->getMobile());
|
||||
}
|
||||
$user->setPasswordHash($this->hasher->hashPassword($user, $password));
|
||||
$user->setRealName($preReg->getName());
|
||||
|
||||
$this->em->persist($user);
|
||||
|
||||
$type = $preReg->getType();
|
||||
|
||||
$doctor = null;
|
||||
if ($type === PreRegistration::TYPE_INDEPENDENT_DOCTOR || $type === PreRegistration::TYPE_DOCTOR_WITH_CLINIC) {
|
||||
$user->addRole('ROLE_DOCTOR');
|
||||
$doctor = $this->doctorRepo->findOneBy(['user' => $user]);
|
||||
if (!$doctor) {
|
||||
$doctor = new Doctor($user, $preReg->getName());
|
||||
$doctor->setMobileNumber($preReg->getMobile());
|
||||
$this->em->persist($doctor);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type === PreRegistration::TYPE_DOCTOR_WITH_CLINIC || $type === PreRegistration::TYPE_CLINIC_MANAGER) {
|
||||
$user->addRole('ROLE_CLINIC');
|
||||
if (!$this->clinicRepo->findOneBy(['user' => $user])) {
|
||||
$clinic = new Clinic($user);
|
||||
$clinic->setName($preReg->getName());
|
||||
$clinic->setTelephone($preReg->getMobile());
|
||||
$clinic->setNotificationMobile($preReg->getMobile());
|
||||
if ($doctor !== null) {
|
||||
$clinic->getDoctors()->add($doctor);
|
||||
}
|
||||
$this->em->persist($clinic);
|
||||
}
|
||||
}
|
||||
|
||||
$preReg->approve();
|
||||
$this->em->flush();
|
||||
|
||||
try {
|
||||
$this->sms->dispatchAsync(
|
||||
$preReg->getMobile(),
|
||||
sprintf(
|
||||
'به کلینیک پرو خوش آمدید! شمارهکاربری: %s | رمز عبور: %s | لینک ورود: https://clinic-pro.ddev.site/admin',
|
||||
$preReg->getMobile(),
|
||||
$password
|
||||
)
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->warning('PreRegistration SMS failed', ['uuid' => $uuid, 'error' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
return $this->success(['message' => 'تأیید شد و اطلاعات ورود ارسال گردید']);
|
||||
}
|
||||
|
||||
#[Route('/api/v1/admin/pre-registrations/{uuid}/reject', methods: ['POST'])]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function reject(string $uuid, Request $request): JsonResponse
|
||||
{
|
||||
$preReg = $this->preRegRepo->findOneBy(['uuid' => $uuid]);
|
||||
if (!$preReg) {
|
||||
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'درخواست یافت نشد', 404);
|
||||
}
|
||||
if (!$preReg->isPending()) {
|
||||
return $this->error(ErrorCodes::ERR_CONFLICT_001, 'این درخواست قبلاً پردازش شده است', 409);
|
||||
}
|
||||
|
||||
$data = json_decode($request->getContent(), true) ?? [];
|
||||
$preReg->reject($data['note'] ?? null);
|
||||
$this->em->flush();
|
||||
|
||||
return $this->success(['message' => 'درخواست رد شد']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Auth\Entity;
|
||||
|
||||
use App\Auth\Repository\PreRegistrationRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PreRegistrationRepository::class)]
|
||||
#[ORM\Table(name: 'pre_registrations')]
|
||||
#[ORM\Index(columns: ['mobile'], name: 'idx_prereg_mobile')]
|
||||
#[ORM\Index(columns: ['status'], name: 'idx_prereg_status')]
|
||||
class PreRegistration
|
||||
{
|
||||
public const TYPE_INDEPENDENT_DOCTOR = 'independent_doctor';
|
||||
public const TYPE_DOCTOR_WITH_CLINIC = 'doctor_with_clinic';
|
||||
public const TYPE_CLINIC_MANAGER = 'clinic_manager';
|
||||
|
||||
public const STATUS_PENDING = 'pending';
|
||||
public const STATUS_APPROVED = 'approved';
|
||||
public const STATUS_REJECTED = 'rejected';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
||||
private string $uuid;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 30)]
|
||||
private string $type;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 255)]
|
||||
private string $name;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 20)]
|
||||
private string $mobile;
|
||||
|
||||
#[ORM\Column(type: 'text', nullable: true)]
|
||||
private ?string $info = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 20)]
|
||||
private string $status = self::STATUS_PENDING;
|
||||
|
||||
#[ORM\Column(name: 'admin_note', type: 'text', nullable: true)]
|
||||
private ?string $adminNote = null;
|
||||
|
||||
#[ORM\Column(name: 'created_at', type: 'integer')]
|
||||
private int $createdAt;
|
||||
|
||||
#[ORM\Column(name: 'updated_at', type: 'integer')]
|
||||
private int $updatedAt;
|
||||
|
||||
public function __construct(string $type, string $name, string $mobile, ?string $info = null)
|
||||
{
|
||||
$this->uuid = Uuid::v4()->toRfc4122();
|
||||
$this->type = $type;
|
||||
$this->name = $name;
|
||||
$this->mobile = $mobile;
|
||||
$this->info = $info;
|
||||
$this->createdAt = time();
|
||||
$this->updatedAt = time();
|
||||
}
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
public function getUuid(): string { return $this->uuid; }
|
||||
public function getType(): string { return $this->type; }
|
||||
public function getName(): string { return $this->name; }
|
||||
public function getMobile(): string { return $this->mobile; }
|
||||
public function getInfo(): ?string { return $this->info; }
|
||||
public function getStatus(): string { return $this->status; }
|
||||
public function getAdminNote(): ?string { return $this->adminNote; }
|
||||
public function getCreatedAt(): int { return $this->createdAt; }
|
||||
public function getUpdatedAt(): int { return $this->updatedAt; }
|
||||
|
||||
public function approve(): void
|
||||
{
|
||||
$this->status = self::STATUS_APPROVED;
|
||||
$this->updatedAt = time();
|
||||
}
|
||||
|
||||
public function reject(?string $note = null): void
|
||||
{
|
||||
$this->status = self::STATUS_REJECTED;
|
||||
$this->adminNote = $note;
|
||||
$this->updatedAt = time();
|
||||
}
|
||||
|
||||
public function isPending(): bool { return $this->status === self::STATUS_PENDING; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Auth\Repository;
|
||||
|
||||
use App\Auth\Entity\PreRegistration;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
class PreRegistrationRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, PreRegistration::class);
|
||||
}
|
||||
|
||||
public function hasPendingForMobile(string $mobile): bool
|
||||
{
|
||||
return (bool) $this->createQueryBuilder('p')
|
||||
->select('1')
|
||||
->where('p.mobile = :mobile')
|
||||
->andWhere('p.status = :status')
|
||||
->setParameter('mobile', $mobile)
|
||||
->setParameter('status', PreRegistration::STATUS_PENDING)
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
||||
+812
-468
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user