Remove code that was never finished and likely won't be used

This commit is contained in:
Calvin Montgomery 2018-08-27 22:07:42 -07:00
parent 553052f901
commit 7b0427afa2
9 changed files with 0 additions and 1434 deletions

View file

@ -1,66 +0,0 @@
import { InvalidRequestError } from '../errors';
const LOGGER = require('@calzoneman/jsli')('AccountDB');
class AccountDB {
constructor(db) {
this.db = db;
}
getByName(name) {
return this.db.runTransaction(async tx => {
const user = await tx.table('users').where({ name }).first();
if (!user) return null;
return this.mapUser(user);
});
}
updateByName(name, changedFields) {
return this.db.runTransaction(async tx => {
if (changedFields.profile) {
changedFields.profile = JSON.stringify(changedFields.profile);
}
const rowsUpdated = await tx.table('users')
.update(changedFields)
.where({ name });
if (rowsUpdated === 0) {
throw new InvalidRequestError(
`Cannot update: name "${name}" does not exist`
);
}
});
}
mapUser(user) {
// Backwards compatibility
// Maybe worth backfilling one day to be done with it?
try {
let profile;
if (!user.profile) {
profile = { image: '', text: '' };
} else {
profile = JSON.parse(user.profile);
}
if (!profile.image) profile.image = '';
if (!profile.text) profile.text = '';
user.profile = profile;
} catch (error) {
// TODO: backfill erroneous records and remove this check
LOGGER.warn('Invalid profile "%s": %s', user.profile, error);
user.profile = { image: '', text: '' };
}
user.time = new Date(user.time);
return user;
}
}
export { AccountDB };

View file

@ -1,102 +0,0 @@
import fs from 'fs';
import path from 'path';
import Promise from 'bluebird';
import { InvalidRequestError } from '../errors';
const unlinkAsync = Promise.promisify(fs.unlink);
class ChannelDB {
constructor(db) {
this.db = db;
}
getByName(name) {
return this.db.runTransaction(async tx => {
const channel = await tx.table('channels')
.where({ name })
.first();
if (!channel) return null;
return this.mapChannel(channel);
});
}
listByOwner(owner) {
return this.db.runTransaction(async tx => {
const rows = await tx.table('channels')
.where({ owner })
.select();
return rows.map(row => this.mapChannel(row));
});
}
insert(params) {
const { name, owner } = params;
return this.db.runTransaction(async tx => {
const existing = await tx.table('channels')
.where({ name })
.forUpdate()
.first();
if (existing) {
throw new InvalidRequestError(
`Channel "${name}" is already registered.`
);
}
await tx.table('channels')
.insert({
name,
owner,
time: Date.now(), // Old column, does not use datetime type
last_loaded: new Date(),
owner_last_seen: new Date()
});
await tx.table('channel_ranks')
.insert({
name: owner,
rank: 5,
channel: name
});
});
}
// TODO: should this be a soft-delete?
deleteByName(name) {
return this.db.runTransaction(async tx => {
const channel = await tx.table('channels')
.where({ name })
.forUpdate()
.first();
if (!channel) return;
await tx.table('channel_ranks').where({ channel: name }).del();
await tx.table('channel_bans').where({ channel: name }).del();
await tx.table('channel_libraries').where({ channel: name }).del();
await tx.table('channel_data').where({ channel_id: channel.id }).del();
await tx.table('channels').where({ name }).del();
// TODO: deprecate and remove flatfile chandumps
const chandump = path.resolve(__dirname, '..', '..', 'chandump', name);
try {
await unlinkAsync(chandump);
} catch (error) {
if (error.code !== 'ENOENT') throw error;
}
});
}
mapChannel(channel) {
// TODO: fix to datetime column?
channel.time = new Date(channel.time);
return channel;
}
}
export { ChannelDB };