actor type, manually set id for user
This commit is contained in:
parent
6ce7e802a6
commit
a789a54fbb
16
src/user.ts
16
src/user.ts
|
@ -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()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue