forked from DebaucheryLibrarian/traxxx
Fixed alert tool to transfer combinations.
This commit is contained in:
@@ -12,45 +12,51 @@ async function save() {
|
||||
.select([
|
||||
'alerts.*',
|
||||
'users.username',
|
||||
'actors.slug as actor_slug',
|
||||
'actors_entities.slug as actor_entity_slug',
|
||||
'actors_entities.type as actor_entity_type',
|
||||
'entities.slug as entity_slug',
|
||||
'entities.type as entity_type',
|
||||
'stashes.slug as stash_slug',
|
||||
'tags.slug as tag_slug',
|
||||
])
|
||||
.leftJoin('users', 'users.id', 'alerts.user_id')
|
||||
.leftJoin('alerts_actors', 'alerts_actors.alert_id', 'alerts.id')
|
||||
.leftJoin('alerts_entities', 'alerts_entities.alert_id', 'alerts.id')
|
||||
.leftJoin('alerts_stashes', 'alerts_stashes.alert_id', 'alerts.id')
|
||||
.leftJoin('alerts_tags', 'alerts_tags.alert_id', 'alerts.id')
|
||||
.leftJoin('actors', 'actors.id', 'alerts_actors.actor_id')
|
||||
.leftJoin('entities', 'entities.id', 'alerts_entities.entity_id')
|
||||
.leftJoin('tags', 'tags.id', 'alerts_tags.tag_id')
|
||||
.leftJoin('stashes', 'stashes.id', 'alerts_stashes.stash_id')
|
||||
.leftJoin('entities as actors_entities', 'actors_entities.id', 'actors.entity_id');
|
||||
.leftJoin('entities', 'entities.id', 'alerts_entities.entity_id');
|
||||
|
||||
let savedAlerts = 0;
|
||||
|
||||
await alerts.reduce(async (chain, alert) => {
|
||||
await chain;
|
||||
|
||||
const curatedAlert = JSON.stringify({
|
||||
const actors = await knex('alerts_actors')
|
||||
.select('actors.slug', 'entities.slug as entity_slug', 'entities.type as entity_type')
|
||||
.leftJoin('actors', 'actors.id', 'alerts_actors.actor_id')
|
||||
.leftJoin('entities', 'entities.id', 'actors.entity_id')
|
||||
.where('alert_id', alert.id);
|
||||
|
||||
const tags = await knex('alerts_tags')
|
||||
.select('tags.slug')
|
||||
.leftJoin('tags', 'tags.id', 'alerts_tags.tag_id')
|
||||
.where('alert_id', alert.id);
|
||||
|
||||
const stashes = await knex('alerts_stashes')
|
||||
.select('stashes.slug')
|
||||
.leftJoin('stashes', 'stashes.id', 'alerts_stashes.stash_id')
|
||||
.where('alert_id', alert.id);
|
||||
|
||||
const curatedAlert = {
|
||||
username: alert.username,
|
||||
notify: alert.notify,
|
||||
email: alert.email,
|
||||
createdAt: alert.created_at,
|
||||
actorSlug: alert.actor_slug,
|
||||
actorEntitySlug: alert.actor_entity_slug,
|
||||
actorEntityType: alert.actor_entity_type,
|
||||
actors: actors.map((actor) => ({
|
||||
slug: actor.slug,
|
||||
entitySlug: actor.entity_slug,
|
||||
entityType: actor.entity_type,
|
||||
})),
|
||||
tags: tags.map((tag) => tag.slug),
|
||||
stashes: stashes.map((stash) => stash.slug),
|
||||
entitySlug: alert.entity_slug,
|
||||
entityType: alert.entity_type,
|
||||
stashSlug: alert.stash_slug,
|
||||
tagSlug: alert.tag_slug,
|
||||
});
|
||||
};
|
||||
|
||||
await fs.promises.appendFile(filename, `${curatedAlert}\n`);
|
||||
await fs.promises.appendFile(filename, `${JSON.stringify(curatedAlert)}\n`);
|
||||
|
||||
console.log(`Saved ${alert.username} alert`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user