52 lines
2.5 KiB
JavaScript
52 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = (sequelize, DataTypes) => {
|
|
const CoachClientLink = sequelize.define('CoachClientLink', {
|
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
|
organizationId: { type: DataTypes.INTEGER, allowNull: false },
|
|
coachId: { type: DataTypes.INTEGER, allowNull: false },
|
|
clientId: { type: DataTypes.INTEGER, allowNull: false },
|
|
isActive: { type: DataTypes.BOOLEAN, defaultValue: true },
|
|
assignedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
|
|
assignedByUserId: { type: DataTypes.INTEGER },
|
|
});
|
|
|
|
const ClientWorkout = sequelize.define('ClientWorkout', {
|
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
|
organizationId: { type: DataTypes.INTEGER, allowNull: false },
|
|
clientId: { type: DataTypes.INTEGER, allowNull: false },
|
|
coachId: { type: DataTypes.INTEGER, allowNull: false },
|
|
name: { type: DataTypes.STRING },
|
|
scheduledDate: { type: DataTypes.DATE },
|
|
notes: { type: DataTypes.TEXT },
|
|
items: {
|
|
type: DataTypes.TEXT,
|
|
defaultValue: '[]',
|
|
get() { try { return JSON.parse(this.getDataValue('items') || '[]'); } catch { return []; } },
|
|
set(v) { this.setDataValue('items', JSON.stringify(v)); },
|
|
},
|
|
completedAt: { type: DataTypes.DATE },
|
|
deletedAt: { type: DataTypes.DATE },
|
|
});
|
|
|
|
ClientWorkout.addScope('active', { where: { deletedAt: null } });
|
|
|
|
const CalendarSession = sequelize.define('CalendarSession', {
|
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
|
organizationId: { type: DataTypes.INTEGER, allowNull: false },
|
|
coachId: { type: DataTypes.INTEGER, allowNull: false },
|
|
clientId: { type: DataTypes.INTEGER },
|
|
title: { type: DataTypes.STRING },
|
|
sessionType: { type: DataTypes.ENUM('personal', 'group', 'assessment', 'other'), defaultValue: 'personal' },
|
|
startAt: { type: DataTypes.DATE, allowNull: false },
|
|
endAt: { type: DataTypes.DATE, allowNull: false },
|
|
locationNotes: { type: DataTypes.STRING },
|
|
coachNotes: { type: DataTypes.TEXT },
|
|
sharedNotes: { type: DataTypes.TEXT },
|
|
status: { type: DataTypes.ENUM('scheduled', 'completed', 'cancelled', 'no-show'), defaultValue: 'scheduled' },
|
|
linkedWorkoutId: { type: DataTypes.INTEGER },
|
|
});
|
|
|
|
return { CoachClientLink, ClientWorkout, CalendarSession };
|
|
};
|