@grouparoo/core
Version:
The Grouparoo Core
86 lines (72 loc) • 1.73 kB
text/typescript
import {
Table,
Column,
AllowNull,
ForeignKey,
BelongsTo,
DataType,
Default,
} from "sequelize-typescript";
import Moment from "moment";
import { App } from "./App";
import { oAuthIdentity, oAuthType } from "../modules/oAuth";
import { CommonModel } from "../classes/commonModel";
import { Op } from "sequelize";
export class OAuthRequest extends CommonModel<OAuthRequest> {
idPrefix() {
return "req";
}
provider: string;
type: oAuthType;
get identities(): oAuthIdentity[] {
return JSON.parse(this.getDataValue("identities") ?? "[]");
}
set identities(value: oAuthIdentity[]) {
this.setDataValue("identities", JSON.stringify(value ?? "[]"));
}
token: string;
consumed: boolean;
appId: string;
appOption: string;
telemetryCustomer: App;
async apiData() {
return {
id: this.id,
type: this.type,
consumed: this.consumed,
provider: this.provider,
token: this.consumed ? null : this.token,
identities: this.consumed ? [] : this.identities,
appId: this.appId,
appOption: this.appOption,
};
}
// --- Class Methods --- //
static async sweep(limit: number) {
const days = 1;
const count = await OAuthRequest.destroy({
where: {
createdAt: { [Op.lt]: Moment().subtract(days, "days").toDate() },
},
limit,
});
return { count, days };
}
}