Files
api/app/core/modules/get-unassigned-devices.ts
T
Alexis Tyler 4e1b0bd72c chore: lint
2021-01-28 15:45:14 +10:30

34 lines
748 B
TypeScript

/*!
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
import { AppError } from '../errors';
import { CoreResult, CoreContext } from '../types';
import { ensurePermission } from '../utils';
/**
* Get all unassigned devices.
*/
export const getUnassignedDevices = async (context: CoreContext): Promise<CoreResult> => {
const { user } = context;
// Bail if the user doesn't have permission
ensurePermission(user, {
resource: 'devices/unassigned',
action: 'read',
possession: 'any'
});
const devices = [];
if (devices.length === 0) {
throw new AppError('No devices found.', 404);
}
return {
text: `Unassigned devices: ${JSON.stringify(devices, null, 2)}`,
json: devices
};
};