v12.0.0 - initial commit
This commit is contained in:
commit
e2c49ea43c
1145 changed files with 97211 additions and 0 deletions
56
packages/server/lib/new-admin/services/machineGroups.js
Normal file
56
packages/server/lib/new-admin/services/machineGroups.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
const { v4: uuid } = require('uuid')
|
||||
const { machineGroups, PG_ERROR_CODES } = require('typesafe-db')
|
||||
const { defaultMachineGroup } = require('../../constants')
|
||||
const {
|
||||
ResourceAlreadyExistsError,
|
||||
ResourceHasDependenciesError,
|
||||
} = require('../graphql/errors')
|
||||
|
||||
async function getAllMachineGroups() {
|
||||
return machineGroups.getMachineGroupsWithDeviceCount()
|
||||
}
|
||||
|
||||
async function createMachineGroup(name) {
|
||||
try {
|
||||
const newGroup = await machineGroups.createMachineGroup({
|
||||
id: uuid(),
|
||||
name,
|
||||
})
|
||||
|
||||
return {
|
||||
...newGroup,
|
||||
deviceCount: 0,
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code === PG_ERROR_CODES.UNIQUE_VIOLATION) {
|
||||
throw new ResourceAlreadyExistsError({ name })
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteMachineGroup(id) {
|
||||
if (id === defaultMachineGroup.uuid) {
|
||||
throw new ResourceHasDependenciesError({ id, name: 'default' })
|
||||
}
|
||||
|
||||
try {
|
||||
return await machineGroups.deleteMachineGroup(id)
|
||||
} catch (error) {
|
||||
if (error.code === PG_ERROR_CODES.FOREIGN_KEY_VIOLATION) {
|
||||
throw new ResourceHasDependenciesError({ id })
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
function assignComplianceTriggerSetToMachineGroup(id, complianceTriggerSetId) {
|
||||
return machineGroups.setComplianceTriggerSetId(id, complianceTriggerSetId)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAllMachineGroups,
|
||||
createMachineGroup,
|
||||
deleteMachineGroup,
|
||||
assignComplianceTriggerSetToMachineGroup,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue