mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
ref: Little refactoring
This commit is contained in:
parent
70cadcd974
commit
3aba4d4a56
14 changed files with 123 additions and 52 deletions
|
@ -15,6 +15,9 @@ const Errors = {
|
|||
LINKED_CARD_NOT_FOUND: {
|
||||
linkedCardNotFound: 'Linked card not found',
|
||||
},
|
||||
LINKED_CARD_OR_NAME_MUST_BE_PRESENT: {
|
||||
linkedCardOrNameMustBePresent: 'Linked card or name must be present',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
@ -31,8 +34,9 @@ module.exports = {
|
|||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
maxLength: 1024,
|
||||
// required: true,
|
||||
allowNull: true,
|
||||
},
|
||||
isCompleted: {
|
||||
type: 'boolean',
|
||||
|
@ -49,6 +53,9 @@ module.exports = {
|
|||
linkedCardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
linkedCardOrNameMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
|
@ -100,19 +107,24 @@ module.exports = {
|
|||
|
||||
const values = _.pick(inputs, ['position', 'name', 'isCompleted']);
|
||||
|
||||
const task = await sails.helpers.tasks.createOne.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
card,
|
||||
values: {
|
||||
...values,
|
||||
taskList,
|
||||
linkedCard,
|
||||
},
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
const task = await sails.helpers.tasks.createOne
|
||||
.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
card,
|
||||
values: {
|
||||
...values,
|
||||
taskList,
|
||||
linkedCard,
|
||||
},
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
})
|
||||
.intercept(
|
||||
'linkedCardOrNameMustBeInValues',
|
||||
() => Errors.LINKED_CARD_OR_NAME_MUST_BE_PRESENT,
|
||||
);
|
||||
|
||||
return {
|
||||
item: task,
|
||||
|
|
|
@ -67,7 +67,7 @@ module.exports = {
|
|||
delete values.position;
|
||||
}
|
||||
|
||||
if (values.list.type === List.Types.CLOSED) {
|
||||
if (List.TYPE_STATE_BY_TYPE[values.list.type] === List.TypeStates.CLOSED) {
|
||||
values.isClosed = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -386,11 +386,13 @@ module.exports = {
|
|||
values.prevListId = null;
|
||||
}
|
||||
|
||||
const typeState = List.TYPE_STATE_BY_TYPE[values.list.type];
|
||||
|
||||
if (inputs.record.isClosed) {
|
||||
if (values.list.type === List.Types.ACTIVE) {
|
||||
if (typeState === List.TypeStates.OPENED) {
|
||||
values.isClosed = false;
|
||||
}
|
||||
} else if (values.list.type === List.Types.CLOSED) {
|
||||
} else if (typeState === List.TypeStates.CLOSED) {
|
||||
values.isClosed = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,9 +34,17 @@ module.exports = {
|
|||
},
|
||||
},
|
||||
|
||||
exists: {
|
||||
linkedCardOrNameMustBeInValues: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!values.linkedCard && !values.name) {
|
||||
throw 'linkedCardOrNameMustBeInValues';
|
||||
}
|
||||
|
||||
const tasks = await Task.qm.getByTaskListId(values.taskList.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
|
|
|
@ -58,10 +58,16 @@ const updateOne = async (criteria, values) => {
|
|||
let tasks = [];
|
||||
|
||||
if (list) {
|
||||
const prevTypeState = List.TYPE_STATE_BY_TYPE[prevList.type];
|
||||
const typeState = List.TYPE_STATE_BY_TYPE[list.type];
|
||||
|
||||
let isClosed;
|
||||
if (list.type === List.Types.ACTIVE) {
|
||||
if (prevTypeState === List.TypeStates.CLOSED && typeState === List.TypeStates.OPENED) {
|
||||
isClosed = false;
|
||||
} else if (list.type === List.Types.CLOSED) {
|
||||
} else if (
|
||||
prevTypeState === List.TypeStates.OPENED &&
|
||||
typeState === List.TypeStates.CLOSED
|
||||
) {
|
||||
isClosed = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,6 @@ const getByTaskListIds = async (taskListIds, { sort = ['position', 'id'] } = {})
|
|||
{ sort },
|
||||
);
|
||||
|
||||
const getByLinkedCardId = (linkedCardId) =>
|
||||
defaultFind({
|
||||
linkedCardId,
|
||||
});
|
||||
|
||||
const getOneById = (id, { taskListId } = {}) => {
|
||||
const criteria = {
|
||||
id,
|
||||
|
@ -68,7 +63,6 @@ module.exports = {
|
|||
getByIds,
|
||||
getByTaskListId,
|
||||
getByTaskListIds,
|
||||
getByLinkedCardId,
|
||||
getOneById,
|
||||
update,
|
||||
updateOne,
|
||||
|
|
|
@ -48,16 +48,16 @@ module.exports = {
|
|||
stopwatch: {
|
||||
type: 'json',
|
||||
},
|
||||
isClosed: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false,
|
||||
columnName: 'is_closed',
|
||||
},
|
||||
commentsTotal: {
|
||||
type: 'number',
|
||||
defaultsTo: 0,
|
||||
columnName: 'comments_total',
|
||||
},
|
||||
isClosed: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false,
|
||||
columnName: 'is_closed',
|
||||
},
|
||||
listChangedAt: {
|
||||
type: 'ref',
|
||||
columnName: 'list_changed_at',
|
||||
|
|
|
@ -17,6 +17,11 @@ const Types = {
|
|||
TRASH: 'trash',
|
||||
};
|
||||
|
||||
const TypeStates = {
|
||||
OPENED: 'opened',
|
||||
CLOSED: 'closed',
|
||||
};
|
||||
|
||||
const SortFieldNames = {
|
||||
NAME: 'name',
|
||||
DUE_DATE: 'dueDate',
|
||||
|
@ -31,6 +36,11 @@ const SortOrders = {
|
|||
|
||||
const FINITE_TYPES = [Types.ACTIVE, Types.CLOSED];
|
||||
|
||||
const TYPE_STATE_BY_TYPE = {
|
||||
[Types.ACTIVE]: TypeStates.OPENED,
|
||||
[Types.CLOSED]: Types.CLOSED,
|
||||
};
|
||||
|
||||
const COLORS = [
|
||||
'berry-red',
|
||||
'pumpkin-orange',
|
||||
|
@ -46,9 +56,11 @@ const COLORS = [
|
|||
|
||||
module.exports = {
|
||||
Types,
|
||||
TypeStates,
|
||||
SortFieldNames,
|
||||
SortOrders,
|
||||
FINITE_TYPES,
|
||||
TYPE_STATE_BY_TYPE,
|
||||
COLORS,
|
||||
|
||||
attributes: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue