actor type, manually set id for user

This commit is contained in:
Moon Man 2024-01-01 07:44:58 -05:00
parent 6ce7e802a6
commit a789a54fbb
1 changed files with 9 additions and 7 deletions

View File

@ -59,8 +59,8 @@ export const getId = async (nickname: string): Promise<number | null> =>
.then((rec) => !!rec ? rec.id : null)
;
export const newUser = async (nickname: string, name: string, bio: string): Promise<number> => {
const { pub, priv } = await (new Promise((resolve, reject) => {
export const newUser = async (nickname: string, name: string, bio: string, actorType = "Person", id?: number): Promise<number> => {
const { public_key, private_key } = await (new Promise((resolve, reject) => {
generateKeyPair("rsa", {
modulusLength: 2048,
publicKeyEncoding: {
@ -71,19 +71,21 @@ export const newUser = async (nickname: string, name: string, bio: string): Prom
type: "pkcs8",
format: "pem"
}
}, (err, pub, priv) => {
}, (err, public_key, private_key) => {
if (err) reject(err);
else resolve({ pub, priv });
else resolve({ public_key, private_key });
})
}) as Promise<{ pub: string, priv: string }>);
}) as Promise<{ public_key: string, private_key: string }>);
return db("users")
.insert({
...(typeof id === "undefined" ? {} : { id }),
actor_type: actorType,
name,
nickname,
bio,
public_key: pub,
private_key: priv,
public_key,
private_key,
deleted: false,
created_at: new Date()
})