82 lines
2.5 KiB
JavaScript

'use strict';
const MainService = require('../main');
class PrintComputerService extends MainService {
constructor(ctx) {
super(ctx);
const _noNeedLogin = '';
const _noNeedRight = '';
const _noNeedLog = '*';
const _noNeedAuth = '';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
/**
* 打印电脑列表。
* @param {Object} data 查询参数 { pagination, where }
* @return {Promise<Object>} 列表数据与分页信息
*/
async list(data) {
try {
const result = await this.service.systems.printComputer.list(data || {});
return this.success('获取成功', result);
} catch (e) { return this.fail(e.message); }
}
/**
* 更新打印电脑。
* @param {Object} data { id, name? }
* @return {Promise<Object>} 更新后的电脑记录
*/
async update(data) {
try {
const { id, ...fields } = data || {};
if (!id) return this.fail('ID不能为空');
return this.success('更新成功', await this.service.systems.printComputer.update(parseInt(id), fields));
} catch (e) { return this.fail(e.message); }
}
/**
* 设置录制电脑(会先取消同仓库下其他录制电脑)。
* @param {Object} data { id, recording_size_value, recording_size_unit, recording_directory }
* @return {Promise<Object>} 设置结果
*/
async setRecording(data) {
try {
const { id, ...fields } = data || {};
if (!id) return this.fail('ID不能为空');
return this.success('设置录制成功', await this.service.systems.printComputer.setRecording(parseInt(id), fields));
} catch (e) { return this.fail(e.message); }
}
/**
* 取消录制电脑。
* @param {Object} data { id }
* @return {Promise<Object>} 取消结果
*/
async cancelRecording(data) {
try {
const { id } = data || {};
if (!id) return this.fail('ID不能为空');
return this.success('取消录制成功', await this.service.systems.printComputer.cancelRecording(parseInt(id)));
} catch (e) { return this.fail(e.message); }
}
/**
* 软删除打印电脑。
* @param {Object} data { id }
* @return {Promise<Object>} 删除结果
*/
async delete(data) {
try {
const { id } = data || {};
if (!id) return this.fail('ID不能为空');
await this.service.systems.printComputer.delete(parseInt(id));
return this.success('删除成功');
} catch (e) { return this.fail(e.message); }
}
}
module.exports = PrintComputerService;