tududi/backend/models/calendar_token.js
Antonis Anastasiadis c24bff1882
Parallelize test running (#166)
* Allow specifying DB file explicitely.

* Export config getter/setter instead of object

Allows dynamically changing configuration

* Remove maxWorker Jest limit, parallelize tests

* Remove unnecessary slow step in Dockerfile.

* Correct error response during login

* Fix setting DB permissions in docker entrypoint

---------

Co-authored-by: antanst <>
2025-07-16 13:27:57 +03:00

81 lines
1.9 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('./models');
const CalendarToken = sequelize.define(
'CalendarToken',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'Users',
key: 'id',
},
onDelete: 'CASCADE',
},
provider: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'google',
},
access_token: {
type: DataTypes.TEXT,
allowNull: false,
},
refresh_token: {
type: DataTypes.TEXT,
allowNull: true,
},
token_type: {
type: DataTypes.STRING,
defaultValue: 'Bearer',
},
expires_at: {
type: DataTypes.DATE,
allowNull: true,
},
scope: {
type: DataTypes.TEXT,
allowNull: true,
},
connected_email: {
type: DataTypes.STRING,
allowNull: true,
},
created_at: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
},
updated_at: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
},
},
{
tableName: 'calendar_tokens',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
indexes: [
{
unique: true,
fields: ['user_id', 'provider'],
},
],
}
);
// Associations
CalendarToken.associate = function (models) {
CalendarToken.belongsTo(models.User, {
foreignKey: 'user_id',
as: 'user',
});
};
module.exports = CalendarToken;