MonEspacePro/backend/src/stores/dto/store.dto.ts
Tony AVERTY a6533f2520 Socle back-end, admin (magasins, carte, employés) et logo
- API NestJS + Prisma (base mep) : auth admin/employés, magasins,
  design de carte avec récompenses et images, comptes du personnel
- Admin Vite/React : liste et fiche magasin, assistant de carte avec
  aperçu Apple/Google Wallet, gestion des employés
- Logo MonEspacePro (Claude Design) en SVG, favicon

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 12:34:26 +02:00

83 lines
2.2 KiB
TypeScript

import { PartialType } from '@nestjs/mapped-types';
import { StoreStatus } from '@prisma/client';
import { Transform } from 'class-transformer';
import {
IsEmail,
IsEnum,
IsIn,
IsInt,
IsOptional,
IsString,
Length,
Matches,
Max,
MaxLength,
Min,
Validate,
ValidatorConstraint,
ValidatorConstraintInterface,
} from 'class-validator';
import { isValidSiret } from '../../common/siret.util';
const trim = ({ value }: { value: unknown }) => (typeof value === 'string' ? value.trim() : value);
/** « 123 456 789 00018 » → « 12345678900018 » */
const digitsOnly = ({ value }: { value: unknown }) => (typeof value === 'string' ? value.replace(/\s/g, '') : value);
@ValidatorConstraint({ name: 'siret' })
class SiretConstraint implements ValidatorConstraintInterface {
validate(value: unknown) {
return typeof value === 'string' && isValidSiret(value);
}
defaultMessage() {
return 'SIRET invalide (14 chiffres, clé de contrôle incorrecte)';
}
}
export class CreateStoreDto {
@Transform(trim) @IsString() @Length(2, 120)
name!: string;
@Transform(digitsOnly) @Validate(SiretConstraint)
siret!: string;
@Transform(trim) @IsString() @Length(3, 200)
addressLine!: string;
@Transform(digitsOnly) @Matches(/^\d{5}$/, { message: 'Code postal : 5 chiffres' })
postalCode!: string;
@Transform(trim) @IsString() @Length(1, 120)
city!: string;
@Transform(trim) @IsString() @Length(2, 120)
contactName!: string;
@Transform(trim) @IsEmail()
contactEmail!: string;
@Transform(digitsOnly) @Matches(/^(\+33|0)[1-9]\d{8}$/, { message: 'Téléphone invalide' })
contactPhone!: string;
/** Plafond d'une opération, en euros entiers (converti en centimes). */
@IsInt() @Min(1) @Max(10_000)
maxAmountEuros!: number;
/** Délai minimum entre deux crédits d'un même client, en minutes. */
@IsInt() @Min(0) @Max(24 * 60)
minScanIntervalMin!: number;
}
export class UpdateStoreDto extends PartialType(CreateStoreDto) {}
export class SetStoreStatusDto {
@IsEnum(StoreStatus)
status!: StoreStatus;
}
export class ListStoresQuery {
@IsOptional() @IsString() @MaxLength(100)
q?: string;
@IsOptional() @IsIn(Object.values(StoreStatus))
status?: StoreStatus;
}