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