Ana içeriğe geç

Kullanıcı sipariş geçmişi

✅ Senaryonun amacı:

  • Kullanıcı kimlik bilgileriyle giriş yapar
  • Kullanıcının sipariş geçmişini alırız

✅ Gerekenler:

  • OneEntry API ile kimlik doğrulama için geçerli bir PROJECT_URL ve APP_TOKEN.
  • Siparişleri olan kayıtlı bir kullanıcı

📌 Önemli:

  • Bu örneklerde hataları ele almıyoruz.
  • Hataları trycatch içinde veya "await Promise.catch((error) => error)" gibi bir yapı ile ele alabilirsiniz.

Senaryo

1. oneEntry'yi içe aktarın ve url ile token'ı tanımlayın

Örnek:

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

2. defineOneEntry() fonksiyonu ile bir API istemcisi oluşturma

Örnek:

const { AuthProvider, Orders } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. AuthProvider.auth() ile kimlik doğrulama

Veri:

[
{
"marker": "email_reg",
"value": "your-user@email.com"
},
{
"marker": "password_reg",
"value": "123456"
}
]

Örnek:

const authResponse = await AuthProvider.auth('email', {
authData,
});
Sonuç:
{
"userIdentifier": "your-user@email.com",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR...pZCI6MTYsImF1dGhQ"
"refreshToken": "1745494429101-...-2834edf8"
}

4. Orders.getAllOrdersByMarker() ile sipariş depolama işaretine göre tüm kullanıcı siparişlerini alma

Örnek:

const allOrders = await Orders.getAllOrdersByMarker('orders', 'en_US', 0, 30);
Sonuç:
{
"items": [
{
"id": 83,
"storageId": 1,
"createdDate": "2025-04-27T22:07:50.620Z",
"statusIdentifier": "upcoming",
"formIdentifier": "order",
"formData": [
{
"type": "string",
"marker": "name",
"value": "Christina Thomas"
}
],
"attributeSetIdentifier": "order",
"totalSum": "340.00",
"currency": "USD",
"paymentAccountIdentifier": "cash",
"paymentAccountLocalizeInfos": {
"title": "Nakit"
},
"products": [
{
"id": 14,
"title": "Yeşil top",
"sku": null,
"previewImage": [],
"price": 340,
"quantity": 1
}
],
"isCompleted": false
},
{
"id": 84,
"storageId": 1,
"createdDate": "2025-04-27T22:08:22.813Z",
"statusIdentifier": "upcoming",
"formIdentifier": "order",
"formData": [
{
"type": "string",
"marker": "name",
"value": "Christina Thomas"
}
],
"attributeSetIdentifier": "order",
"totalSum": "340.00",
"currency": "USD",
"paymentAccountIdentifier": "cash",
"paymentAccountLocalizeInfos": {
"title": "Nakit"
},
"products": [
{
"id": 14,
"title": "Yeşil top",
"sku": null,
"previewImage": [],
"price": 340,
"quantity": 1
}
],
"isCompleted": false
}
],
"total": 2
}

Son örnek

// 1. oneEntry'yi içe aktarın ve PROJECT_URL ile APP_TOKEN'ı tanımlayın
import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

// 2. Bir API istemcisi oluşturma
const { AuthProvider, Orders } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

// 3. AuthProvider.auth() ile kimlik doğrulama
const authData = [
{
marker: 'email_reg',
value: 'your-user@email.com',
},
{
marker: 'password_reg',
value: '123456',
},
];
const authResponse = await AuthProvider.auth('email', {
authData,
});

// 4. Orders.getAllOrdersByMarker() ile sipariş depolama işaretine göre tüm kullanıcı siparişlerini alma
const allOrders = await Orders.getAllOrdersByMarker('orders', 'en_US', 0, 30);
console.log(allOrders);