Skip to content

Instantly share code, notes, and snippets.

@thedewpoint
Created April 19, 2022 01:46
Show Gist options
  • Save thedewpoint/be1ed8e608ba52fb02293ffb30d42645 to your computer and use it in GitHub Desktop.
Save thedewpoint/be1ed8e608ba52fb02293ffb30d42645 to your computer and use it in GitHub Desktop.
import { Entity, Column, ObjectIdColumn, ObjectID } from 'typeorm';
import { DateTime } from 'luxon';
import { UpdateSubscriptionDto } from '../dto/update-subscription.dto';
import { CreateSubscriptionDto } from '../dto/create-subscription.dto';
@Entity('subscriptions')
export class Subscription {
constructor(subscriptionDTO?: UpdateSubscriptionDto | CreateSubscriptionDto) {
this.userId = subscriptionDTO?.userId;
this.active = subscriptionDTO?.active ?? true;
this.createDate =
subscriptionDTO?.createDate ?? DateTime.now().toUTC().toUnixInteger();
if (subscriptionDTO && subscriptionDTO instanceof UpdateSubscriptionDto) {
this.lastBilledAt = subscriptionDTO?.lastBilledAt;
this.id = subscriptionDTO?.id;
}
}
@ObjectIdColumn()
id: ObjectID;
@ObjectIdColumn()
userId: ObjectID;
@ObjectIdColumn()
price: number;
@Column()
createDate: number;
@Column()
lastBilledAt: number;
@Column()
active: boolean;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment