forked from wangziqi/gongxue-base
feat: scaffold supabase multi-tenant backend
This commit is contained in:
12
packages/domain/package-lock.json
generated
Normal file
12
packages/domain/package-lock.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@tiku-saas/domain",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@tiku-saas/domain",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
8
packages/domain/package.json
Normal file
8
packages/domain/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@tiku-saas/domain",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts"
|
||||
}
|
||||
37
packages/domain/src/index.js
Normal file
37
packages/domain/src/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
export const TENANT_ROLES = [
|
||||
'platform_admin',
|
||||
'tenant_owner',
|
||||
'tenant_admin',
|
||||
'tenant_operator',
|
||||
'teacher',
|
||||
'sales',
|
||||
'agent',
|
||||
'student',
|
||||
];
|
||||
export const QUESTION_STATUSES = ['draft', 'published', 'archived'];
|
||||
export const ORDER_STATUSES = ['pending', 'paid', 'failed', 'closed', 'refunded'];
|
||||
export const ENTITLEMENT_SCOPE_TYPES = ['tenant', 'region', 'module', 'subject', 'question_bank'];
|
||||
export function normalizeTenantRole(role) {
|
||||
const value = String(role || '').toLowerCase();
|
||||
if (value === 'superadmin')
|
||||
return 'platform_admin';
|
||||
if (value === 'admin')
|
||||
return 'tenant_admin';
|
||||
if (value === 'operator')
|
||||
return 'tenant_operator';
|
||||
if (TENANT_ROLES.includes(value))
|
||||
return value;
|
||||
return 'student';
|
||||
}
|
||||
export function normalizeOrderStatus(status) {
|
||||
const value = String(status || '').toLowerCase();
|
||||
if (value === 'paid' || value === 'success')
|
||||
return 'paid';
|
||||
if (value === 'failed' || value === 'fail')
|
||||
return 'failed';
|
||||
if (value === 'refunded' || value === 'refund')
|
||||
return 'refunded';
|
||||
if (value === 'closed' || value === 'cancelled' || value === 'canceled')
|
||||
return 'closed';
|
||||
return 'pending';
|
||||
}
|
||||
39
packages/domain/src/index.ts
Normal file
39
packages/domain/src/index.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
export const TENANT_ROLES = [
|
||||
'platform_admin',
|
||||
'tenant_owner',
|
||||
'tenant_admin',
|
||||
'tenant_operator',
|
||||
'teacher',
|
||||
'sales',
|
||||
'agent',
|
||||
'student',
|
||||
] as const;
|
||||
|
||||
export type TenantRole = (typeof TENANT_ROLES)[number];
|
||||
|
||||
export const QUESTION_STATUSES = ['draft', 'published', 'archived'] as const;
|
||||
export type QuestionStatus = (typeof QUESTION_STATUSES)[number];
|
||||
|
||||
export const ORDER_STATUSES = ['pending', 'paid', 'failed', 'closed', 'refunded'] as const;
|
||||
export type OrderStatus = (typeof ORDER_STATUSES)[number];
|
||||
|
||||
export const ENTITLEMENT_SCOPE_TYPES = ['tenant', 'region', 'module', 'subject', 'question_bank'] as const;
|
||||
export type EntitlementScopeType = (typeof ENTITLEMENT_SCOPE_TYPES)[number];
|
||||
|
||||
export function normalizeTenantRole(role: unknown): TenantRole {
|
||||
const value = String(role || '').toLowerCase();
|
||||
if (value === 'superadmin') return 'platform_admin';
|
||||
if (value === 'admin') return 'tenant_admin';
|
||||
if (value === 'operator') return 'tenant_operator';
|
||||
if (TENANT_ROLES.includes(value as TenantRole)) return value as TenantRole;
|
||||
return 'student';
|
||||
}
|
||||
|
||||
export function normalizeOrderStatus(status: unknown): OrderStatus {
|
||||
const value = String(status || '').toLowerCase();
|
||||
if (value === 'paid' || value === 'success') return 'paid';
|
||||
if (value === 'failed' || value === 'fail') return 'failed';
|
||||
if (value === 'refunded' || value === 'refund') return 'refunded';
|
||||
if (value === 'closed' || value === 'cancelled' || value === 'canceled') return 'closed';
|
||||
return 'pending';
|
||||
}
|
||||
Reference in New Issue
Block a user