1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

ability to edit coupon expiration

This commit is contained in:
Sylvain 2016-12-13 12:01:34 +01:00
parent 4817da75d6
commit 85ee73f0e0
5 changed files with 24 additions and 4 deletions

View File

@ -58,8 +58,8 @@ Application.Controllers.controller "NewCouponController", ["$scope", "$state", '
##
# Controller used in the coupon edition page
##
Application.Controllers.controller "EditCouponController", ["$scope", "$state", 'Coupon', 'couponPromise', '_t'
, ($scope, $state, Coupon, couponPromise, _t) ->
Application.Controllers.controller "EditCouponController", ["$scope", "$state", 'Coupon', 'couponPromise', '_t', 'growl'
, ($scope, $state, Coupon, couponPromise, _t, growl) ->
### PUBLIC SCOPE ###

View File

@ -92,7 +92,6 @@
datepicker-options="datePicker.options"
is-open="datePicker.opened"
min-date="datePicker.minDate"
ng-disabled="mode == 'EDIT'"
ng-click="toggleDatePicker($event)"/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="toggleDatePicker($event)" ng-disabled="mode == 'EDIT'"><i class="fa fa-calendar"></i></button>

View File

@ -90,6 +90,6 @@ class API::CouponsController < API::ApiController
end
def coupon_editable_params
params.require(:coupon).permit(:name, :active)
params.require(:coupon).permit(:name, :active, :valid_until)
end
end

View File

@ -11,6 +11,7 @@ class Coupon < ActiveRecord::Base
validates :validity_per_user, presence: true
validates :validity_per_user, inclusion: { in: %w(once forever) }
validates_with CouponDiscountValidator
validates_with CouponExpirationValidator
def safe_destroy
if self.invoices.size == 0
@ -76,6 +77,7 @@ class Coupon < ActiveRecord::Base
attached_object: self
end
private
def create_stripe_coupon
StripeWorker.perform_async(:create_stripe_coupon, id)
end

View File

@ -0,0 +1,19 @@
class CouponExpirationValidator < ActiveModel::Validator
##
# @param record {Coupon}
##
def validate(record)
previous = record.valid_until_was
current = record.valid_until
unless current.blank?
if current.end_of_day < Time.now
record.errors[:valid_until] << 'New expiration date cannot be in the past'
end
if !previous.blank? and current.end_of_day < previous.end_of_day
record.errors[:valid_until] << 'New expiration date cannot be before the previous one'
end
end
end
end