dcb-backoffice/src/app/core/models/merchant-config.model.ts

266 lines
5.8 KiB
TypeScript

// === ENUMS COHÉRENTS ===
export enum UserType {
HUB = 'HUB',
MERCHANT_PARTNER = 'MERCHANT'
}
export enum UserRole {
// Rôles Hub
DCB_ADMIN = 'dcb-admin',
DCB_SUPPORT = 'dcb-support',
// Rôles Merchant User
DCB_PARTNER_ADMIN = 'dcb-partner-admin',
DCB_PARTNER_MANAGER = 'dcb-partner-manager',
DCB_PARTNER_SUPPORT = 'dcb-partner-support',
// Rôles de configuration Marchand (MerchantConfig)
MERCHANT_CONFIG_ADMIN = 'ADMIN',
MERCHANT_CONFIG_MANAGER = 'MANAGER',
MERCHANT_CONFIG_TECHNICAL = 'TECHNICAL',
MERCHANT_CONFIG_VIEWER = 'VIEWER',
}
export enum ConfigType {
API_KEY = 'API_KEY',
SECRET_KEY = 'SECRET_KEY',
WEBHOOK_URL = 'WEBHOOK_URL',
CALLBACK_URL = 'CALLBACK_URL',
TIMEOUT = 'TIMEOUT',
RETRY_COUNT = 'RETRY_COUNT',
CUSTOM = 'CUSTOM'
}
export enum Operator {
ORANGE_OSN = 1
}
// === MODÈLES PRINCIPAUX ===
export interface MerchantConfig {
id?: number
name: ConfigType | string;
value: string;
operatorId: Operator | 1;
merchantPartnerId?: number
createdAt?: string;
updatedAt?: string;
}
export interface TechnicalContact {
id?: number
firstName: string;
lastName: string;
phone: string;
email: string;
merchantPartnerId?: number
createdAt?: string;
updatedAt?: string;
}
export interface MerchantUser {
userId: string;
role: UserRole;
username?: string;
email?: string;
firstName?: string;
lastName?: string;
merchantPartnerId?: number
merchantConfigId?: string; // Référence au merchant dans MerchantConfig
createdAt?: string;
updatedAt?: string;
}
export interface Merchant {
id?: number
name: string;
logo?: string;
description?: string;
adresse: string;
phone: string;
configs: MerchantConfig[];
users: MerchantUser[];
technicalContacts: TechnicalContact[];
createdAt?: string;
updatedAt?: string;
}
// Interfaces pour la réponse API (backend - types number)
export interface ApiMerchantConfig {
id?: number;
name: ConfigType | string;
value: string;
operatorId: Operator | 1;
merchantPartnerId?: number;
createdAt?: string;
updatedAt?: string;
}
export interface ApiTechnicalContact {
id?: number;
firstName: string;
lastName: string;
phone: string;
email: string;
merchantPartnerId?: number;
createdAt?: string;
updatedAt?: string;
}
export interface ApiMerchantUser {
userId: number;
role: UserRole;
username?: string;
email?: string;
firstName?: string;
lastName?: string;
merchantPartnerId?: number;
merchantConfigId?: string;
createdAt?: string;
updatedAt?: string;
}
export interface ApiMerchant {
id?: number;
name: string;
logo?: string;
description?: string;
adresse: string;
phone: string;
configs: ApiMerchantConfig[];
users: ApiMerchantUser[];
technicalContacts: ApiTechnicalContact[];
createdAt?: string;
updatedAt?: string;
}
// === DTOs CRUD ===
export interface CreateMerchantDto {
name: string;
logo?: string;
description?: string;
adresse: string;
phone: string;
configs?: Omit<MerchantConfig, 'id' | 'merchantPartnerId' | 'createdAt' | 'updatedAt'>[];
technicalContacts?: Omit<TechnicalContact, 'id' | 'merchantPartnerId' | 'createdAt' | 'updatedAt'>[];
}
export interface UpdateMerchantDto extends Partial<CreateMerchantDto> {}
// DTO mise à jour d'une configuration
export interface UpdateMerchantConfigDto {
name?: string;
value?: string;
operatorId?: Operator | 1;
}
// DTO mise à jour d'un contact technique
export interface UpdateTechnicalContactDto {
firstName?: string;
lastName?: string;
phone?: string;
email?: string;
}
export interface AddUserToMerchantDto {
userId: string;
role: UserRole;
merchantPartnerId: number;
}
export interface UpdateUserRoleDto {
role: UserRole;
}
// DTO pour associer/dissocier un utilisateur
export interface AssociateUserToMerchantDto {
userId: string;
merchantConfigId: string;
role: UserRole;
}
export interface DissociateUserFromMerchantDto {
userId: string;
merchantConfigId: string;
}
// === RÉPONSES API ===
export interface ApiResponse<T> {
success: boolean;
data?: T;
error?: string;
message?: string;
}
export interface PaginatedResponse<T> {
items: T[];
total: number;
page: number;
limit: number;
totalPages: number;
}
export interface MerchantStatsResponse {
totalMerchants: number;
activeMerchants: number;
inactiveMerchants: number;
pendingMerchants: number;
totalConfigs: number;
totalTechnicalContacts: number;
}
// === SEARCH ===
export interface SearchMerchantsParams {
query?: string;
page?: number;
limit?: number;
}
// === TYPES POUR GESTION DES RÔLES ===
export interface UserRoleInfo {
value: UserRole;
label: string;
description: string;
type: 'hub' | 'merchant' | 'config';
}
// === UTILITAIRES ===
export class MerchantUtils {
static getOperatorName(operatorId: Operator): string {
const operatorNames = {
[Operator.ORANGE_OSN]: 'Orange OSN'
};
return operatorNames[operatorId] || 'Inconnu';
}
static getConfigTypeName(configName: ConfigType | string): string {
const configTypeNames = {
[ConfigType.API_KEY]: 'Clé API',
[ConfigType.SECRET_KEY]: 'Clé Secrète',
[ConfigType.WEBHOOK_URL]: 'URL Webhook',
[ConfigType.CALLBACK_URL]: 'URL Callback',
[ConfigType.TIMEOUT]: 'Timeout (ms)',
[ConfigType.RETRY_COUNT]: 'Nombre de tentatives',
[ConfigType.CUSTOM]: 'Personnalisé'
};
return configTypeNames[configName as ConfigType] || configName;
}
static validateMerchantCreation(merchant: CreateMerchantDto): string[] {
const errors: string[] = [];
if (!merchant.name?.trim()) {
errors.push('Le nom du merchant est requis');
}
if (!merchant.adresse?.trim()) {
errors.push('L\'adresse est requise');
}
if (!merchant.phone?.trim()) {
errors.push('Le téléphone est requis');
}
return errors;
}
}