[NEW] REST endpoints to manage Omnichannel Business Units (#23750)
* add new endpoints to manage business units * change the way deprecations were being returned * change endpoints to be ts * Change to omnichannel * add deprecation warning to old endpointspull/23757/head
parent
d9ccd56426
commit
733af4291c
@ -0,0 +1,9 @@ |
||||
export interface IOmnichannelBusinessUnit { |
||||
_id: string; |
||||
name: string; |
||||
visibility: 'public' | 'private'; |
||||
type: string; |
||||
numMonitors: number; |
||||
numDepartments: number; |
||||
_updatedAt: Date; |
||||
} |
@ -1,42 +0,0 @@ |
||||
import { API } from '../../../../../app/api/server'; |
||||
import { findUnits, findUnitById, findUnitMonitors } from './lib/units'; |
||||
|
||||
API.v1.addRoute('livechat/units.list', { authRequired: true }, { |
||||
get() { |
||||
const { offset, count } = this.getPaginationItems(); |
||||
const { sort } = this.parseJsonQuery(); |
||||
const { text } = this.queryParams; |
||||
|
||||
return API.v1.success(Promise.await(findUnits({ |
||||
userId: this.userId, |
||||
text, |
||||
pagination: { |
||||
offset, |
||||
count, |
||||
sort, |
||||
}, |
||||
}))); |
||||
}, |
||||
}); |
||||
|
||||
API.v1.addRoute('livechat/units.getOne', { authRequired: true }, { |
||||
get() { |
||||
const { unitId } = this.queryParams; |
||||
|
||||
return API.v1.success(Promise.await(findUnitById({ |
||||
userId: this.userId, |
||||
unitId, |
||||
}))); |
||||
}, |
||||
}); |
||||
|
||||
API.v1.addRoute('livechat/unitMonitors.list', { authRequired: true }, { |
||||
get() { |
||||
const { unitId } = this.queryParams; |
||||
|
||||
return API.v1.success(Promise.await(findUnitMonitors({ |
||||
userId: this.userId, |
||||
unitId, |
||||
}))); |
||||
}, |
||||
}); |
@ -0,0 +1,93 @@ |
||||
import { API } from '../../../../../app/api/server'; |
||||
import { deprecationWarning } from '../../../../../app/api/server/helpers/deprecationWarning'; |
||||
import { findUnits, findUnitById, findUnitMonitors } from './lib/units'; |
||||
import { LivechatEnterprise } from '../lib/LivechatEnterprise'; |
||||
import { IOmnichannelBusinessUnit } from '../../../../../definition/IOmnichannelBusinessUnit'; |
||||
|
||||
API.v1.addRoute('livechat/units.list', { authRequired: true }, { |
||||
async get() { |
||||
const { offset, count } = this.getPaginationItems(); |
||||
const { sort } = this.parseJsonQuery(); |
||||
const { text } = this.queryParams; |
||||
|
||||
const response = await findUnits({ |
||||
userId: this.userId, |
||||
text, |
||||
pagination: { |
||||
offset, |
||||
count, |
||||
sort, |
||||
}, |
||||
}); |
||||
|
||||
return API.v1.success(deprecationWarning({ response, endpoint: 'livechat/units.list' })); |
||||
}, |
||||
}); |
||||
|
||||
API.v1.addRoute('livechat/units.getOne', { authRequired: true }, { |
||||
async get() { |
||||
const { id } = this.urlParams; |
||||
const { unit } = await findUnitById({ |
||||
userId: this.userId, |
||||
unitId: id, |
||||
}) as { unit: IOmnichannelBusinessUnit }; |
||||
|
||||
return API.v1.success(deprecationWarning({ response: unit, endpoint: 'livechat/units.getOne' })); |
||||
}, |
||||
}); |
||||
|
||||
API.v1.addRoute('livechat/unitMonitors.list', { authRequired: true }, { |
||||
async get() { |
||||
const { unitId } = this.queryParams; |
||||
|
||||
return API.v1.success(await findUnitMonitors({ |
||||
userId: this.userId, |
||||
unitId, |
||||
})); |
||||
}, |
||||
}); |
||||
|
||||
API.v1.addRoute('livechat/units', { authRequired: true, permissionsRequired: ['manage-livechat-units'] }, { |
||||
async get() { |
||||
const { offset, count } = this.getPaginationItems(); |
||||
const { sort } = this.parseJsonQuery(); |
||||
const { text } = this.queryParams; |
||||
|
||||
return API.v1.success(Promise.await(findUnits({ |
||||
userId: this.userId, |
||||
text, |
||||
pagination: { |
||||
offset, |
||||
count, |
||||
sort, |
||||
}, |
||||
}))); |
||||
}, |
||||
async post() { |
||||
const { unitData, unitMonitors, unitDepartments } = this.bodyParams?.(); |
||||
return LivechatEnterprise.saveUnit(null, unitData, unitMonitors, unitDepartments); |
||||
}, |
||||
}); |
||||
|
||||
API.v1.addRoute('livechat/units/:id', { authRequired: true, permissionsRequired: ['manage-livechat-units'] }, { |
||||
async get() { |
||||
const { id } = this.urlParams; |
||||
const { unit } = await findUnitById({ |
||||
userId: this.userId, |
||||
unitId: id, |
||||
}) as { unit: IOmnichannelBusinessUnit }; |
||||
|
||||
return API.v1.success(unit); |
||||
}, |
||||
async post() { |
||||
const { unitData, unitMonitors, unitDepartments } = this.bodyParams?.(); |
||||
const { id } = this.urlParams; |
||||
|
||||
return LivechatEnterprise.saveUnit(id, unitData, unitMonitors, unitDepartments); |
||||
}, |
||||
async delete() { |
||||
const { id } = this.urlParams; |
||||
|
||||
return LivechatEnterprise.removeUnit(id); |
||||
}, |
||||
}); |
@ -1,4 +1,4 @@ |
||||
import type { EngagementDashboardEndpoints } from './v1/engagementDashboard'; |
||||
import type { OmnichannelBusinessHoursEndpoints } from './v1/omnichannel/businessHours'; |
||||
import type { OmnichannelEndpoints } from './v1/omnichannel'; |
||||
|
||||
export type EnterpriseEndpoints = EngagementDashboardEndpoints & OmnichannelBusinessHoursEndpoints; |
||||
export type EnterpriseEndpoints = EngagementDashboardEndpoints & OmnichannelEndpoints; |
||||
|
@ -0,0 +1,30 @@ |
||||
import { IOmnichannelBusinessUnit } from '../../../../../definition/IOmnichannelBusinessUnit'; |
||||
import { ILivechatMonitor } from '../../../../../definition/ILivechatMonitor'; |
||||
|
||||
type WithPagination<T> = { |
||||
units: T; |
||||
count: number; |
||||
offset: number; |
||||
total: number; |
||||
} |
||||
|
||||
export type OmnichannelBusinessUnitsEndpoints = { |
||||
'livechat/units.list': { |
||||
GET: () => (WithPagination<IOmnichannelBusinessUnit[]>); |
||||
}; |
||||
'livechat/units.getOne': { |
||||
GET: () => (IOmnichannelBusinessUnit); |
||||
}; |
||||
'livechat/unitMonitors.list': { |
||||
GET: () => ({ monitors: ILivechatMonitor[] }); |
||||
}; |
||||
'livechat/units': { |
||||
GET: () => (WithPagination<IOmnichannelBusinessUnit[]>); |
||||
POST: () => IOmnichannelBusinessUnit; |
||||
}; |
||||
'livechat/units/:id': { |
||||
GET: () => IOmnichannelBusinessUnit; |
||||
POST: () => IOmnichannelBusinessUnit; |
||||
DELETE: () => number; |
||||
}; |
||||
} |
@ -0,0 +1,4 @@ |
||||
import type { OmnichannelBusinessHoursEndpoints } from './businessHours'; |
||||
import type { OmnichannelBusinessUnitsEndpoints } from './businessUnits'; |
||||
|
||||
export type OmnichannelEndpoints = OmnichannelBusinessHoursEndpoints & OmnichannelBusinessUnitsEndpoints; |
Loading…
Reference in new issue