RL
Size: a a a
RL
y
RL
RL
RL
VD
NS
y
RL

RL
y
RL
RL
𝕍𝕃
y
R

R
R
import Users from '@models/Users';
import SuperClass from '../SuperClass';
export default class ReqCreateSubid extends SuperClass {
constructor(init) {
// super enable
super(init);
// params
({ req: this.req, res: this.res } = init);
this.preffix = 'arbortag';
// class list
}
async deleteClients(_DB) {
try {
this._DB = _DB;
this._DB[this.preffix] = [];
await this._DB.save();
} catch (err) {
console.error(`❌ [ERROR] ${err}`);
}
}
async pushClients(_DB, subid) {
try {
this._DB = _DB;
this._DB[this.preffix].push(subid);
await this._DB.save();
} catch (err) {
console.error(`❌ [ERROR] ${err}`);
}
}
async run() {
try {
const { access, subid, devRemove } = this.req.query;
const _DB = await Users.findOne({ access }).exec();
if (this.$$isEmpty(_DB)) this.$$throwError(400, 'user not found');
// console.log('dere', devRemove === this.preffix, devRemove);
if (devRemove === this.preffix) await this.deleteClients(_DB);
else {
this.subidExist = await Users.exists({ [this.preffix]: subid });
if (this.subidExist) this.$$throwError(409, '[Subid] already exists');
await this.pushClients(_DB, subid);
}
console.log('_DB update', _DB);
const result = {
serverAnswer: this.$$isEmpty(_DB[this.preffix]) ? ['Empty'] : _DB[this.preffix],
// ,
// debug: { subid, info: _DB || 'empty' }
};
return this.$$goodAnswer(result);
} catch (err) {
this.__console(err);
return this.$$badAnswer(err);
}
}
}
R