mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 01:43:08 +02:00
refactor(server): use insert instead of save
This commit is contained in:
parent
4a64280a7c
commit
6be1db00d1
9 changed files with 19 additions and 18 deletions
|
@ -46,13 +46,13 @@ export async function importUserLists(job: Bull.Job<DbUserImportJobData>, done:
|
|||
});
|
||||
|
||||
if (list == null) {
|
||||
list = await UserLists.save({
|
||||
list = await UserLists.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
userId: user.id,
|
||||
name: listName,
|
||||
userIds: [],
|
||||
});
|
||||
}).then(x => UserLists.findOneOrFail(x.identifiers[0]));
|
||||
}
|
||||
|
||||
let target = isSelfHost(host!) ? await Users.findOne({
|
||||
|
|
|
@ -342,7 +342,7 @@ export async function extractEmojis(tags: IObject | IObject[], host: string): Pr
|
|||
|
||||
logger.info(`register emoji host=${host}, name=${name}`);
|
||||
|
||||
return await Emojis.save({
|
||||
return await Emojis.insert({
|
||||
id: genId(),
|
||||
host,
|
||||
name,
|
||||
|
@ -350,6 +350,6 @@ export async function extractEmojis(tags: IObject | IObject[], host: string): Pr
|
|||
url: tag.icon!.url,
|
||||
updatedAt: new Date(),
|
||||
aliases: [],
|
||||
} as Partial<Emoji>);
|
||||
} as Partial<Emoji>).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -29,14 +29,14 @@ export default function(ctx: Koa.Context, user: ILocalUser, redirect = false) {
|
|||
|
||||
(async () => {
|
||||
// Append signin history
|
||||
const record = await Signins.save({
|
||||
const record = await Signins.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
userId: user.id,
|
||||
ip: ctx.ip,
|
||||
headers: ctx.headers,
|
||||
success: true,
|
||||
});
|
||||
}).then(x => Signins.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
// Publish signin event
|
||||
publishMainStream(user.id, 'signin', await Signins.pack(record));
|
||||
|
|
|
@ -59,14 +59,14 @@ export const meta = {
|
|||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, async (ps) => {
|
||||
const announcement = await Announcements.save({
|
||||
const announcement = await Announcements.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: null,
|
||||
title: ps.title,
|
||||
text: ps.text,
|
||||
imageUrl: ps.imageUrl,
|
||||
});
|
||||
}).then(x => Announcements.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
return announcement;
|
||||
});
|
||||
|
|
|
@ -38,7 +38,7 @@ export default define(meta, async (ps, me) => {
|
|||
|
||||
const name = file.name.split('.')[0].match(/^[a-z0-9_]+$/) ? file.name.split('.')[0] : `_${rndstr('a-z0-9', 8)}_`;
|
||||
|
||||
const emoji = await Emojis.save({
|
||||
const emoji = await Emojis.insert({
|
||||
id: genId(),
|
||||
updatedAt: new Date(),
|
||||
name: name,
|
||||
|
@ -47,7 +47,7 @@ export default define(meta, async (ps, me) => {
|
|||
aliases: [],
|
||||
url: file.url,
|
||||
type: file.type,
|
||||
});
|
||||
}).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
await getConnection().queryResultCache!.remove(['meta_emojis']);
|
||||
|
||||
|
|
|
@ -57,12 +57,12 @@ export default define(meta, async (ps) => {
|
|||
const token = uuid();
|
||||
|
||||
// Create session token document
|
||||
const doc = await AuthSessions.save({
|
||||
const doc = await AuthSessions.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
appId: app.id,
|
||||
token: token,
|
||||
});
|
||||
}).then(x => AuthSessions.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
return {
|
||||
token: doc.token,
|
||||
|
|
|
@ -107,7 +107,7 @@ export default define(meta, async (ps, user) => {
|
|||
}
|
||||
});
|
||||
|
||||
const page = await Pages.save(new Page({
|
||||
const page = await Pages.insert(new Page({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
|
@ -123,7 +123,7 @@ export default define(meta, async (ps, user) => {
|
|||
alignCenter: ps.alignCenter,
|
||||
hideTitleWhenPinned: ps.hideTitleWhenPinned,
|
||||
font: ps.font,
|
||||
}));
|
||||
})).then(x => Pages.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
return await Pages.pack(page);
|
||||
});
|
||||
|
|
|
@ -62,7 +62,7 @@ export default define(meta, async (ps, me) => {
|
|||
throw new ApiError(meta.errors.cannotReportAdmin);
|
||||
}
|
||||
|
||||
const report = await AbuseUserReports.save({
|
||||
const report = await AbuseUserReports.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
targetUserId: user.id,
|
||||
|
@ -70,7 +70,7 @@ export default define(meta, async (ps, me) => {
|
|||
reporterId: me.id,
|
||||
reporterHost: null,
|
||||
comment: ps.comment,
|
||||
});
|
||||
}).then(x => AbuseUserReports.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
// Publish event to moderators
|
||||
setTimeout(async () => {
|
||||
|
|
|
@ -20,7 +20,7 @@ export async function createNotification(
|
|||
const isMuted = profile?.mutingNotificationTypes.includes(type);
|
||||
|
||||
// Create notification
|
||||
const notification = await Notifications.save({
|
||||
const notification = await Notifications.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
notifieeId: notifieeId,
|
||||
|
@ -28,7 +28,8 @@ export async function createNotification(
|
|||
// 相手がこの通知をミュートしているようなら、既読を予めつけておく
|
||||
isRead: isMuted,
|
||||
...data,
|
||||
} as Partial<Notification>);
|
||||
} as Partial<Notification>)
|
||||
.then(x => Notifications.findOneOrFail(x.identifiers[0]));
|
||||
|
||||
const packed = await Notifications.pack(notification, {});
|
||||
|
||||
|
|
Loading…
Reference in a new issue