Files
planka/server/api/models/Card.js

250 lines
6.7 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
2019-08-31 04:07:25 +05:00
/**
* Card.js
*
* @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/
2025-09-08 16:20:27 +02:00
/**
* @swagger
* components:
* schemas:
* Card:
* type: object
* required:
2025-09-08 23:40:36 +02:00
* - id
2025-09-08 16:20:27 +02:00
* - boardId
* - listId
* - type
* - name
* properties:
* id:
* type: string
* description: Unique identifier for the card
2025-09-08 19:14:31 +02:00
* example: "1357158568008091264"
2025-09-08 16:20:27 +02:00
* boardId:
* type: string
* description: ID of the board the card belongs to (denormalized)
2025-09-08 19:14:31 +02:00
* example: "1357158568008091265"
2025-09-08 16:20:27 +02:00
* listId:
* type: string
* description: ID of the list the card belongs to
2025-09-08 19:14:31 +02:00
* example: "1357158568008091266"
2025-09-08 16:20:27 +02:00
* creatorUserId:
* type: string
* nullable: true
* description: ID of the user who created the card
2025-09-08 19:14:31 +02:00
* example: "1357158568008091267"
2025-09-08 16:20:27 +02:00
* prevListId:
* type: string
* nullable: true
* description: ID of the previous list the card was in (available when in archive or trash)
2025-09-08 19:14:31 +02:00
* example: "1357158568008091268"
2025-09-08 16:20:27 +02:00
* coverAttachmentId:
* type: string
* nullable: true
* description: ID of the attachment used as cover
2025-09-08 19:14:31 +02:00
* example: "1357158568008091269"
2025-09-08 16:20:27 +02:00
* type:
* type: string
* enum: [project, story]
* description: Type of the card
* example: project
* position:
* type: number
* nullable: true
* description: Position of the card within the list
* example: 65536
* name:
* type: string
* description: Name/title of the card
* example: Implement user authentication
* description:
* type: string
* nullable: true
* description: Detailed description of the card
* example: Add JWT-based authentication system...
* dueDate:
* type: string
* format: date-time
* nullable: true
* description: Due date for the card
* example: 2024-01-01T00:00:00.000Z
* isDueCompleted:
* type: boolean
* nullable: true
* description: Whether the due date is completed
* example: false
* stopwatch:
* type: object
* required:
* - startedAt
* - total
* nullable: true
* description: Stopwatch data for time tracking
* properties:
* startedAt:
* type: string
* format: date-time
* description: When the stopwatch was started
* example: 2024-01-01T00:00:00.000Z
* total:
* type: number
* description: Total time in seconds
* example: 3600
* commentsTotal:
* type: number
* description: Total number of comments on the card
* example: 100
* isClosed:
* type: boolean
* description: Whether the card is closed
* example: false
* listChangedAt:
* type: string
* format: date-time
* nullable: true
* description: When the card was last moved between lists
* example: 2024-01-01T00:00:00.000Z
* createdAt:
* type: string
* format: date-time
* nullable: true
* description: When the card was created
* example: 2024-01-01T00:00:00.000Z
* updatedAt:
* type: string
* format: date-time
* nullable: true
* description: When the card was last updated
* example: 2024-01-01T00:00:00.000Z
*/
const Types = {
PROJECT: 'project',
STORY: 'story',
};
2019-08-31 04:07:25 +05:00
module.exports = {
Types,
2019-08-31 04:07:25 +05:00
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
type: {
type: 'string',
isIn: Object.values(Types),
required: true,
},
2019-08-31 04:07:25 +05:00
position: {
type: 'number',
allowNull: true,
2019-08-31 04:07:25 +05:00
},
name: {
type: 'string',
required: true,
2019-08-31 04:07:25 +05:00
},
description: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
2019-08-31 04:07:25 +05:00
},
dueDate: {
type: 'ref',
columnName: 'due_date',
2019-08-31 04:07:25 +05:00
},
isDueCompleted: {
type: 'boolean',
allowNull: true,
columnName: 'is_due_completed',
},
stopwatch: {
type: 'json',
2019-08-31 04:07:25 +05:00
},
commentsTotal: {
type: 'number',
defaultsTo: 0,
columnName: 'comments_total',
},
2025-07-14 14:54:06 +02:00
isClosed: {
type: 'boolean',
defaultsTo: false,
columnName: 'is_closed',
},
listChangedAt: {
type: 'ref',
columnName: 'list_changed_at',
},
2019-08-31 04:07:25 +05:00
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝
// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
// Denormalization
2019-08-31 04:07:25 +05:00
boardId: {
model: 'Board',
required: true,
columnName: 'board_id',
2019-08-31 04:07:25 +05:00
},
listId: {
model: 'List',
2022-12-26 21:10:50 +01:00
required: true,
columnName: 'list_id',
},
creatorUserId: {
model: 'User',
columnName: 'creator_user_id',
},
prevListId: {
model: 'List',
columnName: 'prev_list_id',
},
2020-04-23 03:02:53 +05:00
coverAttachmentId: {
model: 'Attachment',
columnName: 'cover_attachment_id',
},
2019-08-31 04:07:25 +05:00
subscriptionUsers: {
collection: 'User',
via: 'cardId',
through: 'CardSubscription',
2019-08-31 04:07:25 +05:00
},
memberUsers: {
2019-08-31 04:07:25 +05:00
collection: 'User',
via: 'cardId',
through: 'CardMembership',
2019-08-31 04:07:25 +05:00
},
labels: {
collection: 'Label',
via: 'cardId',
through: 'CardLabel',
2019-08-31 04:07:25 +05:00
},
taskLists: {
collection: 'TaskList',
via: 'cardId',
},
2020-04-21 05:04:34 +05:00
attachments: {
collection: 'Attachment',
via: 'cardId',
},
comments: {
collection: 'Comment',
via: 'cardId',
},
2020-04-21 05:04:34 +05:00
actions: {
collection: 'Action',
via: 'cardId',
},
},
2019-08-31 04:07:25 +05:00
};