This is the template project that's checked out and configured when you run the bando-up command from ljsthw-bandolier. This is where the code really lives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bandolier-template/commands/unsubkeys.js

16 lines
547 B

import crypto from "crypto";
import { User, UNSUB_CODE_SIZE } from "../lib/models.js";
import { knex } from "../lib/ormish.js";
export const description = "Updates users with no unsubkey, which can happen sometimes when manually adding people.";
export const main = async () => {
for(let u of await User.all({unsubscribe: false, unsubkey: ""})) {
const key = crypto.randomBytes(UNSUB_CODE_SIZE).toString("hex");
console.log(u.id, key, "length", key.length);
await User.update({id: u.id}, {unsubkey: key});
}
knex.destroy();
}