fcb95ecc1a
- `faker` was the original dependency but the maintainer ended up deleting the repo, so development continued in `@faker-js/faker` - we're already using that dependency, so we can make a few simple changes and remove the old dependency from our repo
34 lines
933 B
JavaScript
34 lines
933 B
JavaScript
import moment from 'moment-timezone';
|
|
import {Factory, trait} from 'miragejs';
|
|
import {faker} from '@faker-js/faker';
|
|
|
|
let randomDate = function randomDate(start = moment().subtract(30, 'days').toDate(), end = new Date()) {
|
|
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
|
|
};
|
|
|
|
export default Factory.extend({
|
|
name() { return `${faker.name.firstName()} ${faker.name.lastName()}`; },
|
|
email: faker.internet.email,
|
|
status: 'free',
|
|
createdAt() { return moment.utc(randomDate()).format('YYYY-MM-DD HH:mm:ss'); },
|
|
|
|
free: trait({
|
|
status: 'free'
|
|
}),
|
|
|
|
paid: trait({
|
|
status: 'paid'
|
|
}),
|
|
|
|
comped: trait({
|
|
status: 'comped'
|
|
}),
|
|
|
|
afterCreate(member, server) {
|
|
const newslettersToSignup = server.schema.newsletters.where({subscribeOnSignup: true});
|
|
|
|
member.newsletters = newslettersToSignup;
|
|
member.save();
|
|
}
|
|
});
|