fix(voucher): set value untuk tags. menghapus fungsi sanitizeIntegers() dan unset available_count saat update

This commit is contained in:
Yoga Pangestu 2025-12-08 11:07:59 +07:00
parent 1b14ce5ffb
commit b2069964f5

View File

@ -105,7 +105,7 @@ public function setVoucher(Voucher $voucher)
$this->name = $this->voucher->name;
$this->code = $this->voucher->code;
$this->summary = $this->voucher->summary;
$this->tags = $this->voucher->tags;
$this->type = $this->voucher->type->value;
$this->discount_amount = replaceCurrency($this->voucher->discount_amount);
$this->min_purchase = replaceCurrency($this->voucher->min_purchase);
@ -124,7 +124,6 @@ public function store()
$this->validate();
$data = $this->prepareSavedData();
$data = sanitizeIntegers($data, ['min_purchase', 'max_discount', 'quota', 'limit_per_user', 'available_count']);
DB::transaction(function () use ($data) {
$voucher = Voucher::create($data);
@ -139,6 +138,7 @@ public function update()
$data = $this->prepareSavedData();
DB::transaction(function () use ($data) {
unset($data['available_count']);
$this->voucher->update($data);
$this->voucher->outlets()->sync($this->outlet_ids);
@ -156,7 +156,7 @@ private function prepareSavedData()
'min_purchase' => replaceCurrency($this->min_purchase),
'max_discount' => $this->type == VoucherType::PERCENTAGE->value ? replaceCurrency($this->max_discount) : null,
'quota' => $this->quota,
'available_count' => $this->quota,
'available_count' => $this->quota ?? 0,
'limit_per_user' => $this->limit_per_user,
'summary' => $this->summary,
'start_date' => $this->start_date,