removed unused document methods

This commit is contained in:
Jonathan Barrow 2023-10-02 16:09:25 -04:00
parent faa12036bb
commit cdeac347e0
No known key found for this signature in database
GPG key ID: E86E9FE9049C741F
12 changed files with 6 additions and 171 deletions

View file

@ -70,30 +70,6 @@ const CommunitySchema = new Schema<ICommunity, CommunityModel, ICommunityMethods
}
});
CommunitySchema.method<HydratedCommunityDocument>('upEmpathy', async function upEmpathy(): Promise<void> {
this.empathy_count += 1;
await this.save();
});
CommunitySchema.method<HydratedCommunityDocument>('downEmpathy', async function downEmpathy(): Promise<void> {
this.empathy_count -= 1;
await this.save();
});
CommunitySchema.method<HydratedCommunityDocument>('upFollower', async function upFollower(): Promise<void> {
this.followers += 1;
await this.save();
});
CommunitySchema.method<HydratedCommunityDocument>('downFollower', async function downFollower(): Promise<void> {
this.followers -= 1;
await this.save();
});
CommunitySchema.method<HydratedCommunityDocument>('addUserFavorite', async function addUserFavorite(pid: number): Promise<void> {
if (!this.user_favorites.includes(pid)) {
this.user_favorites.push(pid);

View file

@ -1,5 +1,5 @@
import { Schema, model } from 'mongoose';
import { IContent, IContentMethods, ContentModel, HydratedContentDocument } from '@/types/mongoose/content';
import { IContent, IContentMethods, ContentModel } from '@/types/mongoose/content';
const ContentSchema = new Schema<IContent, ContentModel, IContentMethods>({
pid: Number,
@ -17,34 +17,4 @@ const ContentSchema = new Schema<IContent, ContentModel, IContentMethods>({
}
});
ContentSchema.method<HydratedContentDocument>('addToCommunities', async function addToCommunities(postID) {
this.followed_communities.addToSet(postID);
await this.save();
});
ContentSchema.method<HydratedContentDocument>('removeFromCommunities', async function removeFromCommunities(postID) {
this.followed_communities.pull(postID);
await this.save();
});
ContentSchema.method<HydratedContentDocument>('addToUsers', async function addToUsers(postID) {
this.followed_users.addToSet(postID);
await this.save();
});
ContentSchema.method<HydratedContentDocument>('removeFromUsers', async function removeFromUsers(postID) {
this.followed_users.pull(postID);
await this.save();
});
ContentSchema.method<HydratedContentDocument>('addToFollowers', async function addToFollowers(postID) {
this.following_users.addToSet(postID);
await this.save();
});
ContentSchema.method<HydratedContentDocument>('removeFromFollowers', async function removeFromFollowers(postID) {
this.following_users.pull(postID);
await this.save();
});
export const Content = model<IContent, ContentModel>('Content', ContentSchema);

View file

@ -47,18 +47,4 @@ ConversationSchema.method<HydratedConversationDocument>('newMessage', async func
await this.save();
});
ConversationSchema.method<HydratedConversationDocument>('markAsRead', async function markAsRead(pid) {
const users = this.get('users');
if (users[0].pid === pid) {
users[0].read = true;
} else if (users[1].pid === pid) {
users[1].read = true;
}
this.users = users;
this.markModified('users');
await this.save();
});
export const Conversation = model<IConversation, ConversationModel>('Conversation', ConversationSchema);

View file

@ -1,5 +1,5 @@
import { Schema, model } from 'mongoose';
import { HydratedNotificationDocument, INotification, INotificationMethods, NotificationModel } from '@/types/mongoose/notification';
import { INotification, INotificationMethods, NotificationModel } from '@/types/mongoose/notification';
const NotificationSchema = new Schema<INotification, NotificationModel, INotificationMethods>({
pid: String,
@ -14,9 +14,4 @@ const NotificationSchema = new Schema<INotification, NotificationModel, INotific
lastUpdated: Date
});
NotificationSchema.method<HydratedNotificationDocument>('markRead', async function markRead() {
this.read = true;
await this.save();
});
export const Notification = model<INotification, NotificationModel>('Notification', NotificationSchema);

View file

@ -87,27 +87,6 @@ const PostSchema = new Schema<IPost, PostModel, IPostMethods>({
id: false // * Disables the .id() getter used by Mongoose in TypeScript. Needed to have our own .id field
});
PostSchema.method<HydratedPostDocument>('upReply', async function upReply() {
const replyCount = this.reply_count || 0;
if (replyCount + 1 < 0) {
this.reply_count = 0;
} else {
this.reply_count = replyCount + 1;
}
await this.save();
});
PostSchema.method<HydratedPostDocument>('downReply', async function downReply() {
const replyCount = this.reply_count || 0;
if (replyCount - 1 < 0) {
this.reply_count = 0;
} else {
this.reply_count = replyCount - 1;
}
await this.save();
});
PostSchema.method<HydratedPostDocument>('remove', async function remove(reason) {
this.removed = true;
@ -115,12 +94,6 @@ PostSchema.method<HydratedPostDocument>('remove', async function remove(reason)
await this.save();
});
PostSchema.method<HydratedPostDocument>('unRemove', async function unRemove(reason) {
this.removed = false;
this.removed_reason = reason;
await this.save();
});
PostSchema.method<HydratedPostDocument>('generatePostUID', async function generatePostUID(length: number) {
const id = Buffer.from(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(length * 2))), 'binary').toString('base64').replace(/[+/]/g, '').substring(0, length);

View file

@ -48,46 +48,6 @@ const SettingsSchema = new Schema<ISettings, SettingsModel, ISettingsMethods>({
}
});
SettingsSchema.method<HydratedSettingsDocument>('updateComment', async function updateComment(comment) {
this.profile_comment = comment;
await this.save();
});
SettingsSchema.method<HydratedSettingsDocument>('updateSkill', async function updateSkill(skill) {
this.game_skill = skill;
await this.save();
});
SettingsSchema.method<HydratedSettingsDocument>('commentVisible', async function commentVisible(active) {
this.profile_comment_visibility = active;
await this.save();
});
SettingsSchema.method<HydratedSettingsDocument>('skillVisible', async function skillVisible(active) {
this.game_skill_visibility = active;
await this.save();
});
SettingsSchema.method<HydratedSettingsDocument>('birthdayVisible', async function birthdayVisible(active) {
this.birthday_visibility = active;
await this.save();
});
SettingsSchema.method<HydratedSettingsDocument>('relationshipVisible', async function relationshipVisible(active) {
this.relationship_visibility = active;
await this.save();
});
SettingsSchema.method<HydratedSettingsDocument>('countryVisible', async function countryVisible(active) {
this.country_visibility = active;
await this.save();
});
SettingsSchema.method<HydratedSettingsDocument>('favCommunityVisible', async function favCommunityVisible(active) {
this.profile_favorite_community_visibility = active;
await this.save();
});
SettingsSchema.method<HydratedSettingsDocument>('json', function json(): Record<string, any> {
return {
pid: this.pid,

View file

@ -32,10 +32,6 @@ export interface ICommunity {
}
export interface ICommunityMethods {
upEmpathy(): Promise<void>;
downEmpathy(): Promise<void>;
upFollower(): Promise<void>;
downFollower(): Promise<void>;
addUserFavorite(pid: number): Promise<void>;
delUserFavorite(pid: number): Promise<void>;
json(): Record<string, any>;

View file

@ -7,14 +7,7 @@ export interface IContent {
following_users: Types.Array<number>;
}
export interface IContentMethods {
addToCommunities(): Promise<void>
removeFromCommunities(): Promise<void>
addToUsers(): Promise<void>
removeFromUsers(): Promise<void>
addToFollowers(): Promise<void>
removeFromFollowers(): Promise<void>
}
export interface IContentMethods {}
interface IContentQueryHelpers {}

View file

@ -15,8 +15,7 @@ export interface IConversation {
}
export interface IConversationMethods {
newMessage(message: string, senderPID: number): Promise<void>
markAsRead(pid: number): Promise<void>
newMessage(message: string, senderPID: number): Promise<void>;
}
interface IConversationQueryHelpers {}

View file

@ -15,9 +15,7 @@ export interface INotification {
lastUpdated: number;
}
export interface INotificationMethods {
markRead(): Promise<void>
}
export interface INotificationMethods {}
interface INotificationQueryHelpers {}

View file

@ -40,10 +40,7 @@ export interface IPost {
}
export interface IPostMethods {
upReply(): Promise<void>;
downReply(): Promise<void>;
remove(reason: string): Promise<void>;
unRemove(reason: string): Promise<void>;
generatePostUID(length: number): Promise<void>;
cleanedBody(): string;
cleanedMiiData(): string;

View file

@ -18,15 +18,7 @@ export interface ISettings {
}
export interface ISettingsMethods {
updateComment(comment: string): Promise<void>;
updateSkill(skill: number): Promise<void>;
commentVisible(active: boolean): Promise<void>;
skillVisible(active: boolean): Promise<void>;
birthdayVisible(active: boolean): Promise<void>;
relationshipVisible(active: boolean): Promise<void>;
countryVisible(active: boolean): Promise<void>;
favCommunityVisible(active: boolean): Promise<void>;
json(): Record<string, any>;
json(): Record<string, any>;
}
interface ISettingsQueryHelpers {}