mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
feat(api): allow setting custom fields when creating a card via API (closes #1155)
This commit is contained in:
parent
3126a40bba
commit
ffb9693184
2 changed files with 34 additions and 0 deletions
|
@ -53,6 +53,9 @@ module.exports = {
|
|||
type: 'json',
|
||||
custom: isStopwatch,
|
||||
},
|
||||
customFields: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
|
@ -96,6 +99,10 @@ module.exports = {
|
|||
'stopwatch',
|
||||
]);
|
||||
|
||||
if (inputs.customFields) {
|
||||
values.customFields = inputs.customFields;
|
||||
}
|
||||
|
||||
const card = await sails.helpers.cards.createOne
|
||||
.with({
|
||||
project,
|
||||
|
|
|
@ -75,6 +75,33 @@ module.exports = {
|
|||
listChangedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
if (values.customFields) {
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByBoardId(values.board.id);
|
||||
const customFieldGroupMap = _.keyBy(customFieldGroups, 'name');
|
||||
const customFieldGroupIds = customFieldGroups.map((g) => g.id);
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
const customFieldMap = _.keyBy(customFields, (f) => `${f.customFieldGroupId}:${f.name}`);
|
||||
|
||||
const createValuePromises = [];
|
||||
Object.entries(values.customFields).forEach(([groupName, fields]) => {
|
||||
const group = customFieldGroupMap[groupName];
|
||||
if (!group) return;
|
||||
Object.entries(fields).forEach(([fieldName, content]) => {
|
||||
const field = customFieldMap[`${group.id}:${fieldName}`];
|
||||
if (!field) return;
|
||||
createValuePromises.push(
|
||||
CustomFieldValue.create({
|
||||
cardId: card.id,
|
||||
customFieldGroupId: group.id,
|
||||
customFieldId: field.id,
|
||||
content: String(content),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
await Promise.all(createValuePromises);
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
'cardCreate',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue