Linting
This commit is contained in:
@@ -1,112 +1,124 @@
|
||||
import { DebugBuilder } from "../../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "mongoFeedsWrappers");
|
||||
import {
|
||||
insertDocument,
|
||||
getDocuments,
|
||||
getDocumentByField,
|
||||
updateDocumentByField,
|
||||
deleteDocumentByField,
|
||||
} from "./mongoHandler.mjs";
|
||||
|
||||
const feedCollectionName = 'feeds';
|
||||
const postCollectionName = 'posts';
|
||||
|
||||
// Wrapper for inserting a feed
|
||||
export const createFeed = async (feed) => {
|
||||
try {
|
||||
const insertedId = await insertDocument(feedCollectionName, feed);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
log.ERROR('Error creating feed:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for retrieving all feeds
|
||||
export const getAllFeeds = async () => {
|
||||
try {
|
||||
const feeds = await getDocuments(feedCollectionName);
|
||||
return feeds;
|
||||
} catch (error) {
|
||||
log.ERROR('Error getting all feeds:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for retrieving a feed by link
|
||||
export const getFeedByLink = async (link) => {
|
||||
try {
|
||||
const feed = await getDocumentByField(feedCollectionName, 'link', link);
|
||||
return feed;
|
||||
} catch (error) {
|
||||
log.ERROR('Error getting feed by link:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
insertDocument,
|
||||
getDocuments,
|
||||
getDocumentByField,
|
||||
updateDocumentByField,
|
||||
deleteDocumentByField,
|
||||
} from "./mongoHandler.mjs";
|
||||
|
||||
// Wrapper for retrieving a feed by the title
|
||||
export const getFeedByTitle = async (title) => {
|
||||
try {
|
||||
const feed = await getDocumentByField(feedCollectionName, 'title', title);
|
||||
return feed;
|
||||
} catch (error) {
|
||||
log.ERROR('Error getting feed by link:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for updating a feed by link
|
||||
export const updateFeedByLink = async (link, updatedFields) => {
|
||||
try {
|
||||
const modifiedCount = await updateDocumentByField(feedCollectionName, 'link', link, updatedFields);
|
||||
return modifiedCount;
|
||||
} catch (error) {
|
||||
log.ERROR('Error updating feed by link:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for deleting a feed by link
|
||||
export const deleteFeedByLink = async (link) => {
|
||||
try {
|
||||
const deletedCount = await deleteDocumentByField(feedCollectionName, 'link', link);
|
||||
return deletedCount;
|
||||
} catch (error) {
|
||||
log.ERROR('Error deleting feed by link:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
const feedCollectionName = "feeds";
|
||||
const postCollectionName = "posts";
|
||||
|
||||
// Wrapper for deleting a feed by title
|
||||
export const deleteFeedByTitle = async (title) => {
|
||||
try {
|
||||
const deletedCount = await deleteDocumentByField(feedCollectionName, 'title', title);
|
||||
return deletedCount;
|
||||
} catch (error) {
|
||||
log.ERROR('Error deleting feed by link:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for inserting a post
|
||||
export const createPost = async (post) => {
|
||||
try {
|
||||
const insertedId = await insertDocument(postCollectionName, post);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
log.ERROR('Error creating post:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for retrieving a post by postId
|
||||
export const getPostByPostId = async (postId) => {
|
||||
try {
|
||||
const post = await getDocumentByField(postCollectionName, 'postId', postId);
|
||||
return post;
|
||||
} catch (error) {
|
||||
log.ERROR('Error getting post by postId:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for inserting a feed
|
||||
export const createFeed = async (feed) => {
|
||||
try {
|
||||
const insertedId = await insertDocument(feedCollectionName, feed);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
log.ERROR("Error creating feed:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for retrieving all feeds
|
||||
export const getAllFeeds = async () => {
|
||||
try {
|
||||
const feeds = await getDocuments(feedCollectionName);
|
||||
return feeds;
|
||||
} catch (error) {
|
||||
log.ERROR("Error getting all feeds:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for retrieving a feed by link
|
||||
export const getFeedByLink = async (link) => {
|
||||
try {
|
||||
const feed = await getDocumentByField(feedCollectionName, "link", link);
|
||||
return feed;
|
||||
} catch (error) {
|
||||
log.ERROR("Error getting feed by link:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for retrieving a feed by the title
|
||||
export const getFeedByTitle = async (title) => {
|
||||
try {
|
||||
const feed = await getDocumentByField(feedCollectionName, "title", title);
|
||||
return feed;
|
||||
} catch (error) {
|
||||
log.ERROR("Error getting feed by link:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for updating a feed by link
|
||||
export const updateFeedByLink = async (link, updatedFields) => {
|
||||
try {
|
||||
const modifiedCount = await updateDocumentByField(
|
||||
feedCollectionName,
|
||||
"link",
|
||||
link,
|
||||
updatedFields,
|
||||
);
|
||||
return modifiedCount;
|
||||
} catch (error) {
|
||||
log.ERROR("Error updating feed by link:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for deleting a feed by link
|
||||
export const deleteFeedByLink = async (link) => {
|
||||
try {
|
||||
const deletedCount = await deleteDocumentByField(
|
||||
feedCollectionName,
|
||||
"link",
|
||||
link,
|
||||
);
|
||||
return deletedCount;
|
||||
} catch (error) {
|
||||
log.ERROR("Error deleting feed by link:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for deleting a feed by title
|
||||
export const deleteFeedByTitle = async (title) => {
|
||||
try {
|
||||
const deletedCount = await deleteDocumentByField(
|
||||
feedCollectionName,
|
||||
"title",
|
||||
title,
|
||||
);
|
||||
return deletedCount;
|
||||
} catch (error) {
|
||||
log.ERROR("Error deleting feed by link:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for inserting a post
|
||||
export const createPost = async (post) => {
|
||||
try {
|
||||
const insertedId = await insertDocument(postCollectionName, post);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
log.ERROR("Error creating post:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for retrieving a post by postId
|
||||
export const getPostByPostId = async (postId) => {
|
||||
try {
|
||||
const post = await getDocumentByField(postCollectionName, "postId", postId);
|
||||
return post;
|
||||
} catch (error) {
|
||||
log.ERROR("Error getting post by postId:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user