- implementing immutable.js
This commit is contained in:
16
app/domain/Auction.js
Normal file
16
app/domain/Auction.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Record } from 'immutable';
|
||||
|
||||
export default class Auction extends Record({
|
||||
id: null,
|
||||
bidCount: 0,
|
||||
isBidding: false,
|
||||
isWinning: false,
|
||||
itemPrice: 0,
|
||||
}) {}
|
||||
|
||||
Auction.fromJS = (data = {}) => {
|
||||
return new Auction({
|
||||
id: data._id,
|
||||
...data,
|
||||
});
|
||||
};
|
||||
39
app/domain/Event.js
Normal file
39
app/domain/Event.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { List, Record } from 'immutable';
|
||||
|
||||
import Post from './Post.js';
|
||||
import TicketClass from './TicketClass.js';
|
||||
|
||||
export default class Event extends Record({
|
||||
id: null,
|
||||
isTicketed: false,
|
||||
requireLoginToSeeAuction: false,
|
||||
description: null,
|
||||
endTime: null,
|
||||
images: new List(),
|
||||
posts: new List(),
|
||||
showFrom: null,
|
||||
showUntil: null,
|
||||
startTime: null,
|
||||
tagline: null,
|
||||
title: null,
|
||||
url: null,
|
||||
ticketClasses: new List(),
|
||||
}) {
|
||||
get isSoldOut() {
|
||||
if (this.isTicketed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.ticketClasses.find(t => t.available > 0) || false;
|
||||
}
|
||||
}
|
||||
|
||||
Event.fromJS = (data = {}) => {
|
||||
return new Event({
|
||||
id: data._id,
|
||||
...data,
|
||||
images: new List(data.images),
|
||||
posts: new List(data.posts.map(p => Post.fromJS(p))),
|
||||
ticketClasses: new List(data.ticketClasses.map(t => TicketClass.fromJS(t))),
|
||||
});
|
||||
};
|
||||
43
app/domain/Item.js
Normal file
43
app/domain/Item.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { List, Record } from 'immutable';
|
||||
|
||||
export default class Item extends Record({
|
||||
bidCount: 0,
|
||||
bidIncrement: 10,
|
||||
catalogNumber: null,
|
||||
currentPrice: 0,
|
||||
description: null,
|
||||
donor: null,
|
||||
end: null,
|
||||
estimatedValue: null,
|
||||
eventId: null,
|
||||
hideAfterEnd: false,
|
||||
hideBeforeStart: false,
|
||||
id: null,
|
||||
images: new List(),
|
||||
isShippable: false,
|
||||
notifyOnAvailable: false,
|
||||
quantityAvailable: 1,
|
||||
soldCount: 0,
|
||||
start: null,
|
||||
startingPrice: null,
|
||||
subtitle: null,
|
||||
title: null,
|
||||
type: null,
|
||||
shippingCost: 0,
|
||||
}) {
|
||||
get isSoldOut() {
|
||||
return this.quantityAvailable > this.soldCount;
|
||||
}
|
||||
|
||||
get totalWithShipping() {
|
||||
return this.currentPrice + this.shippingCost;
|
||||
}
|
||||
}
|
||||
|
||||
Item.fromJS = (data = {}) => {
|
||||
return new Item({
|
||||
id: data._id,
|
||||
...data,
|
||||
images: List(data.images),
|
||||
});
|
||||
};
|
||||
20
app/domain/Post.js
Normal file
20
app/domain/Post.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Record } from 'immutable';
|
||||
|
||||
export default class Post extends Record({
|
||||
author: null,
|
||||
content: null,
|
||||
id: null,
|
||||
isPublic: false,
|
||||
scheduledPost: false,
|
||||
sendNotification: false,
|
||||
timestamp: null,
|
||||
title: null,
|
||||
}) {};
|
||||
|
||||
|
||||
Post.fromJS = (data = {}) => {
|
||||
return new TicketClass({
|
||||
id: data._id,
|
||||
...data,
|
||||
});
|
||||
};
|
||||
39
app/domain/Profile.js
Normal file
39
app/domain/Profile.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { List, Record } from 'immutable';
|
||||
|
||||
export default class Profile extends Record({
|
||||
addresses: new List(),
|
||||
avatar: null,
|
||||
email: null,
|
||||
firstName: null,
|
||||
generatedNomDeBid: false,
|
||||
hasLinkedApple: false,
|
||||
hasLinkedFacebook: false,
|
||||
hasLinkedGoogle: false,
|
||||
hasLocalAccount: false,
|
||||
id: null,
|
||||
isAllowedToBid: false,
|
||||
isOrganizationEmployee: false,
|
||||
isVerified: false,
|
||||
lastName: null,
|
||||
nomDeBid: null,
|
||||
organizationIdentifier: null,
|
||||
paymentToken: null,
|
||||
phones: new List(),
|
||||
}) {
|
||||
get canBid() {
|
||||
return this.isAllowedToBid && this.paymentToken !== null;
|
||||
}
|
||||
|
||||
get fullName() {
|
||||
return `${this.firstName} ${this.lastName}`;
|
||||
}
|
||||
}
|
||||
|
||||
Profile.fromJS = (data = {}) => {
|
||||
return new Profile({
|
||||
id: data._id,
|
||||
...data,
|
||||
addresses: new List(data.addresses),
|
||||
phones: new List(data.phones),
|
||||
});
|
||||
};
|
||||
27
app/domain/TicketClass.js
Normal file
27
app/domain/TicketClass.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { List, Record } from 'immutable';
|
||||
|
||||
export default class TicketClass extends Record({
|
||||
available: 0,
|
||||
capacity: 0,
|
||||
endSale: null,
|
||||
id: null,
|
||||
itemId: null,
|
||||
name: null,
|
||||
price: 0,
|
||||
startSale: null,
|
||||
}) {
|
||||
get isAlmostGone() {
|
||||
return this.available < (this.capacity * 0.20);
|
||||
}
|
||||
|
||||
get isSoldOut() {
|
||||
return this.available === 0;
|
||||
}
|
||||
}
|
||||
|
||||
TicketClass.fromJS = (data = {}) => {
|
||||
return new TicketClass({
|
||||
id: data._id,
|
||||
...data,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user