refactor(api & server/utils): refactor imports of db helpers

create an index file which exports the functions we need in one accessible place
This commit is contained in:
parent 0ebc25a1c8
commit 088232f750
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
13 changed files with 23 additions and 22 deletions

@ -0,0 +1,3 @@
export { default as chapterTransformer } from "./chapterTransformer";
export { default as listQuerier } from "./listQuerier";
export { default as storyQuerier } from "./storyQuerier";

@ -1,4 +1,4 @@
import listQuerier from "~/lib/server/dbHelpers/listQuerier";
import { listQuerier } from "~/lib/server/dbHelpers";
import { Band } from "~/models/band";
import { Story } from "~/models/stories";

@ -1,4 +1,4 @@
import listQuerier from "~/lib/server/dbHelpers/listQuerier";
import { listQuerier } from "~/lib/server/dbHelpers";
import { Story } from "~/models/stories";
import { log } from "~/lib/server/logger";

@ -1,8 +1,9 @@
import { messages } from "~/lib/server/constants";
import { Review } from "~/models/stories/review";
import isIdNan from "~/lib/server/middlewareButNotReally/isIdNan";
export default eventHandler(async (ev) => {
const revid = parseInt(getRouterParam(ev, "revid")!);
const revid = isIdNan(ev);
const r = await Review.findById(revid)
.populate("author", "username _id")
.exec();

@ -1,5 +1,5 @@
import chapterTransformer from "~/lib/server/dbHelpers/chapterTransformer";
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import { chapterTransformer } from "~/lib/server/dbHelpers";
import { storyQuerier } from "~/lib/server/dbHelpers";
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
export default eventHandler(async (ev) => {

@ -1,7 +1,7 @@
import { FormChapter } from "~/lib/client/types/form/story";
import { countWords } from "~/lib/functions";
import { messages } from "~/lib/server/constants";
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import { storyQuerier } from "~/lib/server/dbHelpers";
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
import { canModify } from "~/lib/server/middlewareButNotReally/storyPrivileges";
import { replaceOrUploadContent, bodyHandler } from "~/lib/server/storyHelpers";

@ -1,11 +1,10 @@
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import { storyQuerier } from "~/lib/server/dbHelpers";
import { Review } from "~/models/stories/review";
export default eventHandler(async (ev) => {
let story = await storyQuerier(ev);
let comments = await Review.find({
return await Review.find({
whichChapter: story.chapters[ev.context.chapterIndex || 0].id,
replyingTo: null,
});
return comments;
}).exec();
});

@ -1,5 +1,5 @@
import san from "sanitize-html";
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import { storyQuerier } from "~/lib/server/dbHelpers";
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
import { Story } from "~/models/stories";
import { Review } from "~/models/stories/review";

@ -1,6 +1,5 @@
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import chapterTransformer from "~/lib/server/dbHelpers/chapterTransformer";
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
import { storyQuerier } from "~/lib/server/dbHelpers";
import { chapterTransformer } from "~/lib/server/dbHelpers";
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
import { messages } from "~/lib/server/constants";

@ -1,5 +1,5 @@
import { messages } from "~/lib/server/constants";
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import { storyQuerier } from "~/lib/server/dbHelpers";
import { canDelete } from "~/lib/server/middlewareButNotReally/storyPrivileges";
import { Story } from "~/models/stories";

@ -1,7 +1,7 @@
import queryStory from "~/lib/server/dbHelpers/storyQuerier";
import { storyQuerier } from "~/lib/server/dbHelpers";
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
export default eventHandler(async (ev) => {
const story = await queryStory(ev);
const story = await storyQuerier(ev);
let chrs = await storyCheck(ev, story, 0);
if (chrs != null) {
throw createError(chrs);

@ -2,7 +2,7 @@ import { Readable } from "stream";
import { Document } from "mongoose";
import { IStory, Story } from "~/models/stories";
import { FormStory } from "~/lib/client/types/form/story";
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
import { storyQuerier } from "~/lib/server/dbHelpers";
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
import { canModify } from "~/lib/server/middlewareButNotReally/storyPrivileges";
import {

@ -1,11 +1,10 @@
import listQuerier from "~/lib/server/dbHelpers/listQuerier";
import { listQuerier } from "~/lib/server/dbHelpers";
export default cachedEventHandler(async (ev) => {
const id = parseInt(getRouterParam(ev, "id")!);
let s = await listQuerier({ author: { $in: [id] } }, ev.context, ev);
const t = s.stories.map((a) => a.toObject());
return {
stories: t,
total: t.length,
stories: s.stories,
total: s.stories.length,
};
});