78 lines
4.5 KiB
C#
78 lines
4.5 KiB
C#
using FluentValidation;
|
|
using NTP.Application.Common;
|
|
using NTP.Application.Grains.Orders;
|
|
|
|
namespace NTP.Application.Refinery.Wallets;
|
|
|
|
public interface IWalletsRepository
|
|
{
|
|
/// <summary>Oldest first (legacy sort ID ASC).</summary>
|
|
Task<PagedResult<WalletRow>> SearchAsync(WalletsQuery query, PageRequest page, CancellationToken ct = default);
|
|
Task<WalletRow?> GetAsync(long id, CancellationToken ct = default);
|
|
/// <summary>Ids of the ACTIVE records of a truck.</summary>
|
|
Task<IReadOnlyList<long>> GetActiveIdsByTruckAsync(long tn, CancellationToken ct = default);
|
|
/// <summary>Ids of the ACTIVE records of a driver (national number).</summary>
|
|
Task<IReadOnlyList<long>> GetActiveIdsByDriverAsync(long nnpn, CancellationToken ct = default);
|
|
Task<long> InsertAsync(WalletWrite record, string createdBy, CancellationToken ct = default);
|
|
Task SetStatusAsync(long id, string status, string userId, CancellationToken ct = default);
|
|
Task InsertLogAsync(long entityId, string method, string userId, string? userIp, string oldData, string newData, CancellationToken ct = default);
|
|
Task<PagedResult<WalletLogRow>> GetLogAsync(long entityId, PageRequest page, CancellationToken ct = default);
|
|
}
|
|
|
|
public interface IWalletsService
|
|
{
|
|
Task<PagedResult<WalletRow>> SearchAsync(WalletsQuery query, PageRequest page, CancellationToken ct);
|
|
Task<WalletDetail> GetAsync(long id, CancellationToken ct);
|
|
Task<PagedResult<WalletLogRow>> GetLogAsync(long id, PageRequest page, CancellationToken ct);
|
|
Task<WalletsResult> CreateAsync(SaveWalletRequest request, string? userIp, CancellationToken ct);
|
|
Task<WalletsResult> UpdateAsync(long id, SaveWalletRequest request, string? userIp, CancellationToken ct);
|
|
Task<WalletsResult> ActivateAsync(long id, string? userIp, CancellationToken ct);
|
|
Task<WalletsResult> DeactivateAsync(long id, string? userIp, CancellationToken ct);
|
|
Task<ExportFile> ExportAsync(WalletsQuery query, CancellationToken ct);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The form of REFINERY_WALLET.js: required fields per payment method, mobile / bank account / digits formats. Stricter than legacy in two places
|
|
/// only: the truck number (WALLET, BANK) and the wallet number (WALLET, DRIVER_TIP) are required, because the duplicate rule and the payment
|
|
/// need them (every stored record has them).
|
|
/// </summary>
|
|
public sealed class SaveWalletValidator : AbstractValidator<SaveWalletRequest>
|
|
{
|
|
public SaveWalletValidator()
|
|
{
|
|
RuleFor(x => x.PaymentMethod).Must(m => m is WalletValues.MethodWallet or WalletValues.MethodBank or WalletValues.MethodDriverTip)
|
|
.WithMessage(WalletsMessages.Required);
|
|
|
|
When(x => x.PaymentMethod is WalletValues.MethodWallet or WalletValues.MethodBank, () =>
|
|
{
|
|
RuleFor(x => x.Tn).Must(v => WalletsRules.IsDigits(v?.Trim(), 10)).WithMessage(WalletsMessages.Required);
|
|
RuleFor(x => x.OwnerName).NotEmpty().MaximumLength(450).WithMessage(WalletsMessages.Required);
|
|
RuleFor(x => x.OwnerNnpn).Must(v => string.IsNullOrWhiteSpace(v) || WalletsRules.IsDigits(v.Trim(), 15)).WithMessage(WalletsMessages.NumbersOnly);
|
|
});
|
|
|
|
When(x => x.PaymentMethod == WalletValues.MethodWallet, () =>
|
|
{
|
|
RuleFor(x => x.WalletNumber).NotEmpty().WithMessage(WalletsMessages.Required)
|
|
.Must(v => WalletsRules.IsMobile(v?.Trim())).WithMessage(WalletsMessages.WrongMobile);
|
|
});
|
|
|
|
When(x => x.PaymentMethod == WalletValues.MethodBank, () =>
|
|
{
|
|
RuleFor(x => x.Iban).NotEmpty().MaximumLength(50).WithMessage(WalletsMessages.Required);
|
|
RuleFor(x => x.BankAccount).NotEmpty().MaximumLength(50).WithMessage(WalletsMessages.Required)
|
|
.Must(v => WalletsRules.IsBankAccount(v?.Trim())).WithMessage(WalletsMessages.WrongBankAccount);
|
|
RuleFor(x => x.BankName).MaximumLength(300);
|
|
RuleFor(x => x.BankBranch).MaximumLength(50);
|
|
RuleFor(x => x.OwnerNameEnglish).MaximumLength(150);
|
|
});
|
|
|
|
When(x => x.PaymentMethod == WalletValues.MethodDriverTip, () =>
|
|
{
|
|
RuleFor(x => x.DriverName).NotEmpty().MaximumLength(450).WithMessage(WalletsMessages.Required);
|
|
RuleFor(x => x.DriverNnpn).Must(v => WalletsRules.IsDigits(v?.Trim(), 15)).WithMessage(WalletsMessages.Required);
|
|
RuleFor(x => x.WalletNumber).NotEmpty().WithMessage(WalletsMessages.Required)
|
|
.Must(v => WalletsRules.IsMobile(v?.Trim())).WithMessage(WalletsMessages.WrongMobile);
|
|
});
|
|
}
|
|
}
|