Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Web App CI / test (push) Waiting to run
Web App CI / build (push) Blocked by required conditions
Deploy Admin Panel / Deploy Admin Panel (push) Waiting to run
Deploy Admin Panel / Admin Panel Verification (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
60 lines
2.1 KiB
Dart
60 lines
2.1 KiB
Dart
import 'package:mnemo_cards_backend/discounts/discount_drift_extension.dart';
|
|
import 'package:mnemo_cards_backend/extensions.dart';
|
|
import 'package:mnemo_cards_backend/repository/export.dart';
|
|
import 'package:mnemo_cards_common_backend/mnemo_cards_common_backend.dart';
|
|
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
|
|
|
extension DiscountCampaignModelExt on DiscountCampaignModel {
|
|
Future<DiscountCampaignDto> toDto(
|
|
DiscountRepository discountRepository,
|
|
) async {
|
|
final discounts = await discountRepository.getDiscountsByCampaignId(id!);
|
|
return DiscountCampaignDto(
|
|
id: id,
|
|
start: this.start,
|
|
finish: this.finish,
|
|
status: status.toDto(),
|
|
name: name,
|
|
tags: this.tags,
|
|
discounts: discounts.map((d) => d.toDto()).toList(),
|
|
);
|
|
}
|
|
}
|
|
|
|
extension DiscountExt on DiscountModel {
|
|
DiscountDto toDto() => DiscountDto(
|
|
discountPercent: discountPercent,
|
|
products: products.map((p) => p.toDto()).toList(),
|
|
id: id?.toString(),
|
|
);
|
|
}
|
|
|
|
extension DiscountModelExt on DiscountDto {
|
|
DiscountModel toModel() => DiscountModel(
|
|
discountPercent: discountPercent,
|
|
products: products.map((p) => p.toModel()).toBaseList(),
|
|
id: id,
|
|
);
|
|
}
|
|
|
|
extension DiscountCampaignModelStatusExt on DiscountCampaignModelStatus {
|
|
DiscountCampaignStatus toDto() {
|
|
return switch (this) {
|
|
DiscountCampaignModelStatus.created => DiscountCampaignStatus.created,
|
|
DiscountCampaignModelStatus.active => DiscountCampaignStatus.active,
|
|
DiscountCampaignModelStatus.expired => DiscountCampaignStatus.expired,
|
|
DiscountCampaignModelStatus.disabled => DiscountCampaignStatus.disabled,
|
|
};
|
|
}
|
|
}
|
|
|
|
extension DiscountCampaignStatusExt on DiscountCampaignStatus {
|
|
DiscountCampaignModelStatus toModel() {
|
|
return switch (this) {
|
|
DiscountCampaignStatus.created => DiscountCampaignModelStatus.created,
|
|
DiscountCampaignStatus.active => DiscountCampaignModelStatus.active,
|
|
DiscountCampaignStatus.disabled => DiscountCampaignModelStatus.disabled,
|
|
DiscountCampaignStatus.expired => DiscountCampaignModelStatus.expired,
|
|
};
|
|
}
|
|
}
|