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
3
lib/server/dbHelpers/index.ts
Normal file
3
lib/server/dbHelpers/index.ts
Normal file
@ -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 { Band } from "~/models/band";
|
||||||
import { Story } from "~/models/stories";
|
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 { Story } from "~/models/stories";
|
||||||
import { log } from "~/lib/server/logger";
|
import { log } from "~/lib/server/logger";
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { messages } from "~/lib/server/constants";
|
import { messages } from "~/lib/server/constants";
|
||||||
import { Review } from "~/models/stories/review";
|
import { Review } from "~/models/stories/review";
|
||||||
|
import isIdNan from "~/lib/server/middlewareButNotReally/isIdNan";
|
||||||
|
|
||||||
export default eventHandler(async (ev) => {
|
export default eventHandler(async (ev) => {
|
||||||
const revid = parseInt(getRouterParam(ev, "revid")!);
|
const revid = isIdNan(ev);
|
||||||
const r = await Review.findById(revid)
|
const r = await Review.findById(revid)
|
||||||
.populate("author", "username _id")
|
.populate("author", "username _id")
|
||||||
.exec();
|
.exec();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import chapterTransformer from "~/lib/server/dbHelpers/chapterTransformer";
|
import { chapterTransformer } from "~/lib/server/dbHelpers";
|
||||||
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
|
import { storyQuerier } from "~/lib/server/dbHelpers";
|
||||||
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
|
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
|
||||||
|
|
||||||
export default eventHandler(async (ev) => {
|
export default eventHandler(async (ev) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { FormChapter } from "~/lib/client/types/form/story";
|
import { FormChapter } from "~/lib/client/types/form/story";
|
||||||
import { countWords } from "~/lib/functions";
|
import { countWords } from "~/lib/functions";
|
||||||
import { messages } from "~/lib/server/constants";
|
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 isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
||||||
import { canModify } from "~/lib/server/middlewareButNotReally/storyPrivileges";
|
import { canModify } from "~/lib/server/middlewareButNotReally/storyPrivileges";
|
||||||
import { replaceOrUploadContent, bodyHandler } from "~/lib/server/storyHelpers";
|
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";
|
import { Review } from "~/models/stories/review";
|
||||||
|
|
||||||
export default eventHandler(async (ev) => {
|
export default eventHandler(async (ev) => {
|
||||||
let story = await storyQuerier(ev);
|
let story = await storyQuerier(ev);
|
||||||
let comments = await Review.find({
|
return await Review.find({
|
||||||
whichChapter: story.chapters[ev.context.chapterIndex || 0].id,
|
whichChapter: story.chapters[ev.context.chapterIndex || 0].id,
|
||||||
replyingTo: null,
|
replyingTo: null,
|
||||||
});
|
}).exec();
|
||||||
return comments;
|
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import san from "sanitize-html";
|
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 isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
||||||
import { Story } from "~/models/stories";
|
import { Story } from "~/models/stories";
|
||||||
import { Review } from "~/models/stories/review";
|
import { Review } from "~/models/stories/review";
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import storyQuerier from "~/lib/server/dbHelpers/storyQuerier";
|
import { storyQuerier } from "~/lib/server/dbHelpers";
|
||||||
import chapterTransformer from "~/lib/server/dbHelpers/chapterTransformer";
|
import { chapterTransformer } from "~/lib/server/dbHelpers";
|
||||||
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
|
|
||||||
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
||||||
import { messages } from "~/lib/server/constants";
|
import { messages } from "~/lib/server/constants";
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { messages } from "~/lib/server/constants";
|
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 { canDelete } from "~/lib/server/middlewareButNotReally/storyPrivileges";
|
||||||
import { Story } from "~/models/stories";
|
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";
|
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
|
||||||
export default eventHandler(async (ev) => {
|
export default eventHandler(async (ev) => {
|
||||||
const story = await queryStory(ev);
|
const story = await storyQuerier(ev);
|
||||||
let chrs = await storyCheck(ev, story, 0);
|
let chrs = await storyCheck(ev, story, 0);
|
||||||
if (chrs != null) {
|
if (chrs != null) {
|
||||||
throw createError(chrs);
|
throw createError(chrs);
|
||||||
|
@ -2,7 +2,7 @@ import { Readable } from "stream";
|
|||||||
import { Document } from "mongoose";
|
import { Document } from "mongoose";
|
||||||
import { IStory, Story } from "~/models/stories";
|
import { IStory, Story } from "~/models/stories";
|
||||||
import { FormStory } from "~/lib/client/types/form/story";
|
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 isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
||||||
import { canModify } from "~/lib/server/middlewareButNotReally/storyPrivileges";
|
import { canModify } from "~/lib/server/middlewareButNotReally/storyPrivileges";
|
||||||
import {
|
import {
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import listQuerier from "~/lib/server/dbHelpers/listQuerier";
|
import { listQuerier } from "~/lib/server/dbHelpers";
|
||||||
|
|
||||||
export default cachedEventHandler(async (ev) => {
|
export default cachedEventHandler(async (ev) => {
|
||||||
const id = parseInt(getRouterParam(ev, "id")!);
|
const id = parseInt(getRouterParam(ev, "id")!);
|
||||||
let s = await listQuerier({ author: { $in: [id] } }, ev.context, ev);
|
let s = await listQuerier({ author: { $in: [id] } }, ev.context, ev);
|
||||||
const t = s.stories.map((a) => a.toObject());
|
|
||||||
return {
|
return {
|
||||||
stories: t,
|
stories: s.stories,
|
||||||
total: t.length,
|
total: s.stories.length,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user