Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/unit/handlers/work.orders.handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ test('handlers: cancelWorkOrder maps to updateThing with status=cancelled', asyn
t.is(flow.lastPush.params[0].info.cancelReason, 'duplicate')
})

test('handlers: reopenWorkOrder maps to updateThing with status=open and clears closedAt', async (t) => {
const flow = buildSubmitFlow()
await handlers.reopenWorkOrder(flow.ctx, {
...userMeta(),
params: { id: 'wo-1' },
body: { reason: 'rework needed' }
})
t.is(flow.lastPush.action, 'updateThing')
t.is(flow.lastPush.params[0].id, 'wo-1')
t.is(flow.lastPush.params[0].info.status, 'open')
t.is(flow.lastPush.params[0].info.closedAt, null, 'clears closedAt')
t.is(flow.lastPush.params[0].info.reopenReason, 'rework needed')
})

test('handlers: assignWorkOrder maps to updateThing with assignedTo', async (t) => {
const flow = buildSubmitFlow()
await handlers.assignWorkOrder(flow.ctx, {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/routes/work.orders.routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test('work.orders.routes: registers every WO endpoint', (t) => {
{ method: HTTP_METHODS.PATCH, url: ENDPOINTS.WORK_ORDER_BY_ID },
{ method: HTTP_METHODS.POST, url: ENDPOINTS.WORK_ORDER_CLOSE },
{ method: HTTP_METHODS.POST, url: ENDPOINTS.WORK_ORDER_CANCEL },
{ method: HTTP_METHODS.POST, url: ENDPOINTS.WORK_ORDER_REOPEN },
{ method: HTTP_METHODS.POST, url: ENDPOINTS.WORK_ORDER_ASSIGN },
{ method: HTTP_METHODS.POST, url: ENDPOINTS.WORK_ORDER_LOG },
{ method: HTTP_METHODS.GET, url: ENDPOINTS.WORK_ORDER_EXPORT },
Expand Down
4 changes: 3 additions & 1 deletion workers/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ const ENDPOINTS = {
WORK_ORDER_ASSIGN: '/auth/work-orders/:id/assign',
WORK_ORDER_CLOSE: '/auth/work-orders/:id/close',
WORK_ORDER_CANCEL: '/auth/work-orders/:id/cancel',
WORK_ORDER_REOPEN: '/auth/work-orders/:id/reopen',
// Spare Part endpoints
SPARE_PARTS: '/auth/spare-parts',
SPARE_PARTS_BATCH: '/auth/spare-parts/batch',
Expand Down Expand Up @@ -267,7 +268,8 @@ const OPERATIONS = {
WORK_ORDER_UPDATE: 'work_order.update',
WORK_ORDER_CLOSE: 'work_order.close',
WORK_ORDER_CANCEL: 'work_order.cancel',
WORK_ORDER_ASSIGN: 'work_order.assign'
WORK_ORDER_ASSIGN: 'work_order.assign',
WORK_ORDER_REOPEN: 'work_order.reopen'
}

const DEFAULTS = {
Expand Down
7 changes: 7 additions & 0 deletions workers/lib/server/handlers/work.orders.handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ async function cancelWorkOrder (ctx, req) {
return submitWorkOrderAction(ctx, req, 'updateThing', { id: req.params.id, info })
}

async function reopenWorkOrder (ctx, req) {
const info = { status: 'open', closedAt: null }
if (req.body?.reason) info.reopenReason = req.body.reason
return submitWorkOrderAction(ctx, req, 'updateThing', { id: req.params.id, info })
}

async function assignWorkOrder (ctx, req) {
return submitWorkOrderAction(ctx, req, 'updateThing', {
id: req.params.id,
Expand Down Expand Up @@ -332,6 +338,7 @@ module.exports = {
updateWorkOrder,
closeWorkOrder,
cancelWorkOrder,
reopenWorkOrder,
assignWorkOrder,
appendWorkLogEntry,
getWorkOrderAudit,
Expand Down
7 changes: 7 additions & 0 deletions workers/lib/server/routes/work.orders.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
updateWorkOrder,
closeWorkOrder,
cancelWorkOrder,
reopenWorkOrder,
assignWorkOrder,
appendWorkLogEntry,
getWorkOrderAudit,
Expand Down Expand Up @@ -105,6 +106,12 @@ module.exports = (ctx) => [
schema: schemas.cancel,
...createAuthRoute(ctx, cancelWorkOrder, [AUTH_PERMISSIONS.WORK_ORDER])
},
{
method: HTTP_METHODS.POST,
url: ENDPOINTS.WORK_ORDER_REOPEN,
schema: schemas.reopen,
...createAuthRoute(ctx, reopenWorkOrder, [AUTH_PERMISSIONS.WORK_ORDER])
},
{
method: HTTP_METHODS.POST,
url: ENDPOINTS.WORK_ORDER_ASSIGN,
Expand Down
11 changes: 10 additions & 1 deletion workers/lib/server/schemas/work.orders.schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ const cancel = {
}
}

const reopen = {
params: byId.params,
body: {
type: 'object',
additionalProperties: false,
properties: { reason: { type: 'string', minLength: 1, maxLength: 2000 } }
}
}

const assign = {
params: byId.params,
body: {
Expand Down Expand Up @@ -238,4 +247,4 @@ const exportRma = {
}
}

module.exports = { create, createBatch, list, byId, update, close, cancel, assign, audit, log, export: exportRoute, exportRma }
module.exports = { create, createBatch, list, byId, update, close, cancel, reopen, assign, audit, log, export: exportRoute, exportRma }
Loading