import Snowflake from "./snowflake";
import UserClient from "./userClient";
import User from "./user";
import { RequestContext } from "./requestContext";
import { prisma } from "../../prisma";
/**
* Handles info about users premium
*/
class Premium {
id: Snowflake;
ctx: RequestContext;
started: Date;
user: User;
client: UserClient;
paypal: string;
/**
* @param {Object} param0 Premium details
*/
constructor({
id,
started,
user,
paypal
}: {
id: Snowflake,
started: Date,
user: UserClient,
paypal: string
}) {
this.id = id;
this.ctx = user.ctx;
this.started = started;
this.client = user;
this.paypal = paypal;
this.user = this.client.user;
}
/**
* Updates the premium details
* @return {Promise<void>}
*/
async update(): Promise<void> {
await prisma.premium.update({
where: {
snowflake: this.id.toBigInt()
},
data: {
paypal: this.paypal
}
});
}
/**
* Cancels the membership
* @return {Promise<void>}
*/
cancel(): Promise<void> {
this.paypal = "";
return this.update();
}
/**
* Creates a JSON-compatible object
* @return {Object}
*/
toJSON() {
return {
id: this.id.getSnowflake(),
started: this.started.toJSON(),
user: this.user.toJSON(),
paypal: this.paypal
};
}
}
export default Premium;
Source