طلب التذاكر
✅ هدف السيناريو:
- يقوم المستخدم بتسجيل الدخول باستخدام بيانات اعتماده
- يختار نوع التذكرة، التاريخ والوقت من الجدول
- يدفع مقابل الطلب ويتلقى تذكرة عبر البريد الإلكتروني
✅ ما تحتاجه:
- عنوان مشروع صالح (PROJECT_URL) ورمز تطبيق (APP_TOKEN) للمصادقة مع واجهة برمجة التطبيقات OneEntry.
- مستخدم مسجل للمصادقة
- نموذج بعلامة "tickets_form" وحقول "schedule" و "tickets"
- تخزين الطلبات المكونة بعلامة "tickets"
📌 مهم:
- نحن لا نتعامل مع الأخطاء في هذه الأمثلة.
- يمكنك التعامل مع الأخطاء في trycatch أو في بناء مثل "await Promise.catch((error) => error)"
السيناريو
1. استيراد oneEntry وتحديد عنوان URL ورمز التطبيق
مثال:
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. إنشاء عميل API باستخدام دالة defineOneEntry()
مثال:
const { AuthProvider, Forms, Orders, Payments } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. مصادقة المستخدم باستخدام AuthProvider.auth()
البيانات:
[
{
"marker": "email_reg",
"value": "your-user@email.com"
},
{
"marker": "password_reg",
"value": "123456"
}
]
مثال:
const authResponse = await AuthProvider.auth('email', {
authData,
});
النتيجة:
{
"userIdentifier": "your-user@email.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}
4. نتلقى بيانات النموذج من OneEntry CMS باستخدام Forms.getFormByMarker() لإنشاء نموذج على الواجهة الأمامية
مثال:
const formData = await Forms.getFormByMarker('tickets_form');
النتيجة:
{
"id": 9,
"attributeSetId": 12,
"type": "order",
"localizeInfos": {
"title": "التذاكر",
"titleForSite": "التذاكر",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"version": 6,
"position": 1,
"identifier": "tickets_form",
"processingType": "script",
"templateId": null,
"attributes": [
{
"type": "timeInterval",
"marker": "schedule",
"isLogin": null,
"isSignUp": null,
"position": 1,
"settings": {},
"isVisible": true,
"listTitles": [],
"validators": {},
"localizeInfos": {
"title": "الجدول",
"intervals": [
{
"id": "ef9cf848-7373-4b81-98bd-7ad33aa951e2",
"range": [
"2025-04-26T21:00:00.000Z",
"2025-04-26T21:00:00.000Z"
],
"external": [],
"intervals": [
{
"id": "f2042e47-c650-4fc6-ae1c-efdb109b450f",
"end": {
"hours": 21,
"minutes": 30
},
"start": {
"hours": 16,
"minutes": 30
},
"period": 90
}
],
"inEveryWeek": true,
"inEveryMonth": true
}
]
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
},
{
"type": "entity",
"marker": "tickets",
"isLogin": null,
"isSignUp": null,
"position": 2,
"settings": {},
"isVisible": true,
"listTitles": [
{
"id": 8,
"depth": 0,
"title": "التذاكر",
"parentId": null,
"position": "0|hzzzz3:"
},
{
"id": "p-8-10",
"depth": 1,
"title": "برونز",
"parentId": 8,
"position": 1,
"selected": true
},
{
"id": "p-8-11",
"depth": 1,
"title": "فضة",
"parentId": 8,
"position": 2,
"selected": true
},
{
"id": "p-8-12",
"depth": 1,
"title": "ذهب",
"parentId": 8,
"position": 3,
"selected": true
}
],
"validators": {
"requiredValidator": {
"strict": true
}
},
"localizeInfos": {
"title": "التذاكر"
},
"additionalFields": [],
"isNotificationEmail": null,
"isNotificationPhoneSMS": null,
"isNotificationPhonePush": null
}
]
}