From aa6af848814c2671f20ac1e50d1d67fbe7701d47 Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Wed, 9 Oct 2024 18:21:01 -0400 Subject: [PATCH 01/15] Translated src/posts/data.js to ts and compiled it to a new js file --- src/posts/data.js | 88 ++++++++++++++++++++++++++++++----------------- src/posts/data.ts | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 32 deletions(-) create mode 100644 src/posts/data.ts diff --git a/src/posts/data.js b/src/posts/data.js index 3a4d303ff5..53f4904b5e 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -1,7 +1,26 @@ 'use strict'; +const __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P((resolve) => { resolve(value); }); } + const res = new (P || (P = Promise))((resolve, reject) => { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { + if (result.done) { + resolve(result.value); + } else { + adopt(result.value).then(fulfilled, rejected); + } + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + return res; +}; + const db = require('../database'); + const plugins = require('../plugins'); + const utils = require('../utils'); const intFields = [ @@ -9,49 +28,54 @@ const intFields = [ 'upvotes', 'downvotes', 'deleterUid', 'edited', 'replies', 'bookmarks', ]; - module.exports = function (Posts) { - Posts.getPostsFields = async function (pids, fields) { - if (!Array.isArray(pids) || !pids.length) { - return []; - } - const keys = pids.map(pid => `post:${pid}`); - const postData = await db.getObjects(keys, fields); - const result = await plugins.hooks.fire('filter:post.getFields', { - pids: pids, - posts: postData, - fields: fields, + Posts.getPostsFields = function (pids, fields) { + return __awaiter(this, undefined, undefined, function* () { + if (!Array.isArray(pids) || !pids.length) { + return []; + } + const keys = pids.map(pid => `post:${pid}`); + const postData = yield db.getObjects(keys, fields); + const result = yield plugins.hooks.fire('filter:post.getFields', { + pids: pids, + posts: postData, + fields: fields, + }); + result.posts.forEach(post => modifyPost(post, fields)); + return result.posts; }); - result.posts.forEach(post => modifyPost(post, fields)); - return result.posts; }; - Posts.getPostData = async function (pid) { const posts = await Posts.getPostsFields([pid], []); return posts && posts.length ? posts[0] : null; }; - - Posts.getPostsData = async function (pids) { - return await Posts.getPostsFields(pids, []); + Posts.getPostsData = function (pids) { + return __awaiter(this, undefined, undefined, function* () { + return yield Posts.getPostsFields(pids, []); + }); }; - - Posts.getPostField = async function (pid, field) { - const post = await Posts.getPostFields(pid, [field]); - return post ? post[field] : null; + Posts.getPostField = function (pid, field) { + return __awaiter(this, undefined, undefined, function* () { + const post = yield Posts.getPostFields(pid, [field]); + return post ? post[field] : null; + }); }; - - Posts.getPostFields = async function (pid, fields) { - const posts = await Posts.getPostsFields([pid], fields); - return posts ? posts[0] : null; + Posts.getPostFields = function (pid, fields) { + return __awaiter(this, undefined, undefined, function* () { + const posts = yield Posts.getPostsFields([pid], fields); + return posts ? posts[0] : null; + }); }; - - Posts.setPostField = async function (pid, field, value) { - await Posts.setPostFields(pid, { [field]: value }); + Posts.setPostField = function (pid, field, value) { + return __awaiter(this, undefined, undefined, function* () { + yield Posts.setPostFields(pid, { [field]: value }); + }); }; - - Posts.setPostFields = async function (pid, data) { - await db.setObject(`post:${pid}`, data); - plugins.hooks.fire('action:post.setFields', { data: { ...data, pid } }); + Posts.setPostFields = function (pid, data) { + return __awaiter(this, undefined, undefined, function* () { + yield db.setObject(`post:${pid}`, data); + plugins.hooks.fire('action:post.setFields', { data: { ...data, pid } }); + }); }; }; diff --git a/src/posts/data.ts b/src/posts/data.ts new file mode 100644 index 0000000000..28c271a5be --- /dev/null +++ b/src/posts/data.ts @@ -0,0 +1,72 @@ +'use strict'; + +import { any } from "async"; +const db = require('./src/database'); +const plugins = require('./src/plugins'); +const utils = require('./src/utils'); + +let intFields: string[] = [ + 'uid', 'pid', 'tid', 'deleted', 'timestamp', + 'upvotes', 'downvotes', 'deleterUid', 'edited', + 'replies', 'bookmarks', +]; + +export default function (Posts: any):any { + Posts.getPostsFields = async function (pids:string[], fields: string[]) { + if (!Array.isArray(pids) || !pids.length) { + return []; + } + const keys = pids.map(pid => `post:${pid}`); + const postData = await db.getObjects(keys, fields); + const result = await plugins.hooks.fire('filter:post.getFields', { + pids: pids, + posts: postData, + fields: fields, + }); + result.posts.forEach((post: any) => modifyPost(post, fields)); + return result.posts; + }; + + Posts.getPostData = async function (pid:string) { + const posts = await Posts.getPostsFields([pid], []); + return posts && posts.length ? posts[0] : null; + }; + + Posts.getPostsData = async function (pids:string[]) { + return await Posts.getPostsFields(pids, []); + }; + + Posts.getPostField = async function (pid:string, field:string) { + const post = await Posts.getPostFields(pid, [field]); + return post ? post[field] : null; + }; + + Posts.getPostFields = async function (pid:string, fields:string) { + const posts = await Posts.getPostsFields([pid], fields); + return posts ? posts[0] : null; + }; + + Posts.setPostField = async function (pid:string, field:string, value:string) { + await Posts.setPostFields(pid, { [field]: value }); + }; + + Posts.setPostFields = async function (pid:String, data:any) { + await db.setObject(`post:${pid}`, data); + plugins.hooks.fire('action:post.setFields', { data: { ...data, pid } }); + }; +}; + +function modifyPost(post:any, fields:string[]): void { + if (post) { + db.parseIntFields(post, intFields, fields); + if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { + post.votes = post.upvotes - post.downvotes; + } + if (post.hasOwnProperty('timestamp')) { + post.timestampISO = utils.toISOString(post.timestamp); + } + if (post.hasOwnProperty('edited')) { + post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; + } + } +} From 605cfac529da3376d20f63481cdc31a15d6e2c75 Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Thu, 10 Oct 2024 19:55:13 -0400 Subject: [PATCH 02/15] Fix data.ts to pass linter --- src/posts/data.ts | 159 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 113 insertions(+), 46 deletions(-) diff --git a/src/posts/data.ts b/src/posts/data.ts index 28c271a5be..4f6b8c89d0 100644 --- a/src/posts/data.ts +++ b/src/posts/data.ts @@ -1,72 +1,139 @@ -'use strict'; +import { getObjects, setObject, parseIntFields } from '../database'; +import { Hooks } from '../plugins/hooks'; +import { utils } from '../utils'; -import { any } from "async"; -const db = require('./src/database'); -const plugins = require('./src/plugins'); -const utils = require('./src/utils'); - -let intFields: string[] = [ +const intFields: string[] = [ 'uid', 'pid', 'tid', 'deleted', 'timestamp', 'upvotes', 'downvotes', 'deleterUid', 'edited', 'replies', 'bookmarks', ]; -export default function (Posts: any):any { - Posts.getPostsFields = async function (pids:string[], fields: string[]) { +interface Post { + votes: number; + upvotes: number; + downvotes: number; + timestamp: number; + timestampISO: string; + edited: number; + editedISO: string; +} + +interface Utils { + toISOString: (timestamp: number) => string; + } + +declare const utils:Utils; +declare const hooks:Hooks; +declare const getObjects: (keys: string[], fields: string[]) => Promise; + +function modifyPost(post:Post, fields:string[]): void { + if (post) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + parseIntFields(post, intFields, fields); + if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { + post.votes = post.upvotes - post.downvotes; + } + if (post.hasOwnProperty('timestamp')) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + post.timestampISO = utils.toISOString(post.timestamp); + } + if (post.hasOwnProperty('edited')) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; + } + } +} + + + +export default class Posts { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + static async getPostsFields(pids:string[], fields: string[]): Promise { if (!Array.isArray(pids) || !pids.length) { return []; } const keys = pids.map(pid => `post:${pid}`); - const postData = await db.getObjects(keys, fields); - const result = await plugins.hooks.fire('filter:post.getFields', { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + const postData: Post[] = await getObjects(keys, fields); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + const result: { pids: string[], posts: Post[], fields: string[] } = await hooks.fire('filter:post.getFields', { pids: pids, posts: postData, fields: fields, }); - result.posts.forEach((post: any) => modifyPost(post, fields)); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + result.posts.forEach((post: Post) => modifyPost(post, fields)); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call return result.posts; - }; + } - Posts.getPostData = async function (pid:string) { - const posts = await Posts.getPostsFields([pid], []); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + static async getPostData(pid:string): Promise { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + const posts:object[] = await Posts.getPostsFields([pid], []); return posts && posts.length ? posts[0] : null; - }; + } - Posts.getPostsData = async function (pids:string[]) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + static async getPostsData(pids:string[]):Promise { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call return await Posts.getPostsFields(pids, []); - }; + } - Posts.getPostField = async function (pid:string, field:string) { - const post = await Posts.getPostFields(pid, [field]); - return post ? post[field] : null; - }; + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + static async getPostField(pid:string, field:string): Promise { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + const post: object = await Posts.getPostFields(pid, [field]); + if (post) { + return post[field]; + } + return null; + } - Posts.getPostFields = async function (pid:string, fields:string) { - const posts = await Posts.getPostsFields([pid], fields); - return posts ? posts[0] : null; - }; + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + static async getPostFields(pid:string, fields:string[]): Promise { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + const posts: object[] = await Posts.getPostsFields([pid], fields); + if (posts && posts.length) { + return posts[0]; + } + return null; + } - Posts.setPostField = async function (pid:string, field:string, value:string) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + static async setPostField(pid:string, field:string, value:string):Promise { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call await Posts.setPostFields(pid, { [field]: value }); - }; - - Posts.setPostFields = async function (pid:String, data:any) { - await db.setObject(`post:${pid}`, data); - plugins.hooks.fire('action:post.setFields', { data: { ...data, pid } }); - }; -}; + } -function modifyPost(post:any, fields:string[]): void { - if (post) { - db.parseIntFields(post, intFields, fields); - if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { - post.votes = post.upvotes - post.downvotes; - } - if (post.hasOwnProperty('timestamp')) { - post.timestampISO = utils.toISOString(post.timestamp); - } - if (post.hasOwnProperty('edited')) { - post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; - } + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + static async setPostFields(pid:string, data:object): Promise { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + await setObject(`post:${pid}`, data); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + Hooks.fire('action:post.setFields', { data: { ...data, pid } }); } } + + From 8f1180b57dae419d178cdb1e6f78a066fbfb0c70 Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Thu, 10 Oct 2024 20:28:30 -0400 Subject: [PATCH 03/15] Fix line 93 and 65 from not passing lint --- src/posts/data.ts | 47 ++++++++++------------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/src/posts/data.ts b/src/posts/data.ts index 4f6b8c89d0..31802c219e 100644 --- a/src/posts/data.ts +++ b/src/posts/data.ts @@ -50,8 +50,6 @@ function modifyPost(post:Post, fields:string[]): void { export default class Posts { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call static async getPostsFields(pids:string[], fields: string[]): Promise { if (!Array.isArray(pids) || !pids.length) { return []; @@ -61,71 +59,46 @@ export default class Posts { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call const postData: Post[] = await getObjects(keys, fields); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment const result: { pids: string[], posts: Post[], fields: string[] } = await hooks.fire('filter:post.getFields', { pids: pids, posts: postData, fields: fields, }); - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call result.posts.forEach((post: Post) => modifyPost(post, fields)); - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call return result.posts; } - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call static async getPostData(pid:string): Promise { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call const posts:object[] = await Posts.getPostsFields([pid], []); return posts && posts.length ? posts[0] : null; } - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call static async getPostsData(pids:string[]):Promise { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call return await Posts.getPostsFields(pids, []); } - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - static async getPostField(pid:string, field:string): Promise { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - const post: object = await Posts.getPostFields(pid, [field]); - if (post) { - return post[field]; + static async getPostFields(pid:string, fields:string[]): Promise { + const posts: object[] = await Posts.getPostsFields([pid], fields); + if (posts && posts.length) { + return posts[0]; } return null; } - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - static async getPostFields(pid:string, fields:string[]): Promise { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - const posts: object[] = await Posts.getPostsFields([pid], fields); - if (posts && posts.length) { - return posts[0]; + static async getPostField(pid:string, field:string): Promise { + const post: object = await Posts.getPostFields(pid, [field]); + if (post) { + return post[field] as object; } return null; } - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call static async setPostField(pid:string, field:string, value:string):Promise { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call await Posts.setPostFields(pid, { [field]: value }); } - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call static async setPostFields(pid:string, data:object): Promise { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call From 29a9afdbf6e41116260dbcce9a7e6acefa478a69 Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Fri, 11 Oct 2024 22:01:42 -0400 Subject: [PATCH 04/15] Re-compiling data.ts into data.js --- src/posts/data.js | 187 +++++++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 86 deletions(-) diff --git a/src/posts/data.js b/src/posts/data.js index 53f4904b5e..e27c2d3025 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -1,95 +1,110 @@ -'use strict'; +"use strict"; -const __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P((resolve) => { resolve(value); }); } - const res = new (P || (P = Promise))((resolve, reject) => { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } - function step(result) { - if (result.done) { - resolve(result.value); - } else { - adopt(result.value).then(fulfilled, rejected); - } - } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); - return res; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); }; -const db = require('../database'); - -const plugins = require('../plugins'); +Object.defineProperty(exports, "__esModule", { value: true }); +const database_1 = require("../database"); +const hooks = require("../plugins/hooks"); const utils = require('../utils'); - const intFields = [ - 'uid', 'pid', 'tid', 'deleted', 'timestamp', - 'upvotes', 'downvotes', 'deleterUid', 'edited', - 'replies', 'bookmarks', + 'uid', 'pid', 'tid', 'deleted', 'timestamp', + 'upvotes', 'downvotes', 'deleterUid', 'edited', + 'replies', 'bookmarks', ]; -module.exports = function (Posts) { - Posts.getPostsFields = function (pids, fields) { - return __awaiter(this, undefined, undefined, function* () { - if (!Array.isArray(pids) || !pids.length) { - return []; - } - const keys = pids.map(pid => `post:${pid}`); - const postData = yield db.getObjects(keys, fields); - const result = yield plugins.hooks.fire('filter:post.getFields', { - pids: pids, - posts: postData, - fields: fields, - }); - result.posts.forEach(post => modifyPost(post, fields)); - return result.posts; - }); - }; - Posts.getPostData = async function (pid) { - const posts = await Posts.getPostsFields([pid], []); - return posts && posts.length ? posts[0] : null; - }; - Posts.getPostsData = function (pids) { - return __awaiter(this, undefined, undefined, function* () { - return yield Posts.getPostsFields(pids, []); - }); - }; - Posts.getPostField = function (pid, field) { - return __awaiter(this, undefined, undefined, function* () { - const post = yield Posts.getPostFields(pid, [field]); - return post ? post[field] : null; - }); - }; - Posts.getPostFields = function (pid, fields) { - return __awaiter(this, undefined, undefined, function* () { - const posts = yield Posts.getPostsFields([pid], fields); - return posts ? posts[0] : null; - }); - }; - Posts.setPostField = function (pid, field, value) { - return __awaiter(this, undefined, undefined, function* () { - yield Posts.setPostFields(pid, { [field]: value }); - }); - }; - Posts.setPostFields = function (pid, data) { - return __awaiter(this, undefined, undefined, function* () { - yield db.setObject(`post:${pid}`, data); - plugins.hooks.fire('action:post.setFields', { data: { ...data, pid } }); - }); - }; +function modifyPost(post, fields) { + if (post) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + (0, database_1.parseIntFields)(post, intFields, fields); + if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { + post.votes = post.upvotes - post.downvotes; + } + if (post.hasOwnProperty('timestamp')) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + post.timestampISO = utils.toISOString(post.timestamp); + } + if (post.hasOwnProperty('edited')) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; + } + } }; -function modifyPost(post, fields) { - if (post) { - db.parseIntFields(post, intFields, fields); - if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { - post.votes = post.upvotes - post.downvotes; - } - if (post.hasOwnProperty('timestamp')) { - post.timestampISO = utils.toISOString(post.timestamp); - } - if (post.hasOwnProperty('edited')) { - post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; - } - } -} +module.exports = function (Posts){ + Posts.getPostsFields = function(pids, fields) { + return __awaiter(this, void 0, void 0, function* () { + if (!Array.isArray(pids) || !pids.length) { + return []; + } + const keys = pids.map(pid => `post:${pid}`); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + const postData = yield database_1.getObjects(keys, fields); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + const result = yield hooks.fire('filter:post.getFields', { + pids: pids, + posts: postData, + fields: fields, + }); + result.posts.forEach((post) => modifyPost(post, fields)); + return result.posts; + }); + }; + Posts.getPostData = async function(pid) { + return __awaiter(this, void 0, void 0, function* () { + const posts = yield Posts.getPostsFields([pid], []); + return posts && posts.length ? posts[0] : null; + }); + }; + Posts.getPostsData = function(pids) { + return __awaiter(this, void 0, void 0, function* () { + return yield Posts.getPostsFields(pids, []); + }); + }; + Posts.getPostFields = function(pid, fields) { + return __awaiter(this, void 0, void 0, function* () { + const posts = yield Posts.getPostsFields([pid], fields); + if (posts && posts.length) { + return posts[0]; + } + return null; + }); + }; + Posts.getPostField = function(pid, field) { + return __awaiter(this, void 0, void 0, function* () { + const post = yield Posts.getPostFields(pid, [field]); + if (post) { + return post[field]; + } + return null; + }); + }; + Posts.setPostField = function(pid, field, value) { + return __awaiter(this, void 0, void 0, function* () { + yield Posts.setPostFields(pid, { [field]: value }); + }); + }; + Posts.setPostFields = function(pid, data) { + return __awaiter(this, void 0, void 0, function* () { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + yield (0, database_1.setObject)(`post:${pid}`, data); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + hooks.fire('action:post.setFields', { data: Object.assign(Object.assign({}, data), { pid }) }); + }); + }; +} \ No newline at end of file From 0d75739c30c3cba9bf9120e516beee3548cc84ad Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Fri, 11 Oct 2024 22:17:34 -0400 Subject: [PATCH 05/15] Added async property to data.js functions --- src/posts/data.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/posts/data.js b/src/posts/data.js index e27c2d3025..838537ea0c 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -42,7 +42,7 @@ function modifyPost(post, fields) { }; module.exports = function (Posts){ - Posts.getPostsFields = function(pids, fields) { + Posts.getPostsFields = async function(pids, fields) { return __awaiter(this, void 0, void 0, function* () { if (!Array.isArray(pids) || !pids.length) { return []; @@ -69,12 +69,12 @@ module.exports = function (Posts){ return posts && posts.length ? posts[0] : null; }); }; - Posts.getPostsData = function(pids) { + Posts.getPostsData = async function(pids) { return __awaiter(this, void 0, void 0, function* () { return yield Posts.getPostsFields(pids, []); }); }; - Posts.getPostFields = function(pid, fields) { + Posts.getPostFields = async function(pid, fields) { return __awaiter(this, void 0, void 0, function* () { const posts = yield Posts.getPostsFields([pid], fields); if (posts && posts.length) { @@ -83,7 +83,7 @@ module.exports = function (Posts){ return null; }); }; - Posts.getPostField = function(pid, field) { + Posts.getPostField = async function(pid, field) { return __awaiter(this, void 0, void 0, function* () { const post = yield Posts.getPostFields(pid, [field]); if (post) { @@ -92,12 +92,12 @@ module.exports = function (Posts){ return null; }); }; - Posts.setPostField = function(pid, field, value) { + Posts.setPostField = async function(pid, field, value) { return __awaiter(this, void 0, void 0, function* () { yield Posts.setPostFields(pid, { [field]: value }); }); }; - Posts.setPostFields = function(pid, data) { + Posts.setPostFields = async function(pid, data) { return __awaiter(this, void 0, void 0, function* () { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call From 15e0cb138150ee1fd26306e1ca3ce05980e99532 Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Fri, 11 Oct 2024 22:23:01 -0400 Subject: [PATCH 06/15] Remove line that might make github actions fail --- src/posts/data.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/posts/data.js b/src/posts/data.js index 838537ea0c..7c1b419045 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; -Object.defineProperty(exports, "__esModule", { value: true }); const database_1 = require("../database"); const hooks = require("../plugins/hooks"); const utils = require('../utils'); From b6d8152ca7366dddc8baa267e22e75a2fdbe8e3b Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Fri, 11 Oct 2024 22:30:46 -0400 Subject: [PATCH 07/15] Fix a push and commit mistake --- src/posts/data.js | 90 ++++++++++++++----------------------- src/posts/data.ts | 112 ---------------------------------------------- 2 files changed, 33 insertions(+), 169 deletions(-) delete mode 100644 src/posts/data.ts diff --git a/src/posts/data.js b/src/posts/data.js index 53f4904b5e..9457778f66 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -1,26 +1,7 @@ 'use strict'; -const __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P((resolve) => { resolve(value); }); } - const res = new (P || (P = Promise))((resolve, reject) => { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } - function step(result) { - if (result.done) { - resolve(result.value); - } else { - adopt(result.value).then(fulfilled, rejected); - } - } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); - return res; -}; - const db = require('../database'); - const plugins = require('../plugins'); - const utils = require('../utils'); const intFields = [ @@ -28,54 +9,49 @@ const intFields = [ 'upvotes', 'downvotes', 'deleterUid', 'edited', 'replies', 'bookmarks', ]; + module.exports = function (Posts) { - Posts.getPostsFields = function (pids, fields) { - return __awaiter(this, undefined, undefined, function* () { - if (!Array.isArray(pids) || !pids.length) { - return []; - } - const keys = pids.map(pid => `post:${pid}`); - const postData = yield db.getObjects(keys, fields); - const result = yield plugins.hooks.fire('filter:post.getFields', { - pids: pids, - posts: postData, - fields: fields, - }); - result.posts.forEach(post => modifyPost(post, fields)); - return result.posts; + Posts.getPostsFields = async function (pids, fields) { + if (!Array.isArray(pids) || !pids.length) { + return []; + } + const keys = pids.map(pid => `post:${pid}`); + const postData = await db.getObjects(keys, fields); + const result = await plugins.hooks.fire('filter:post.getFields', { + pids: pids, + posts: postData, + fields: fields, }); + result.posts.forEach(post => modifyPost(post, fields)); + return result.posts; }; + Posts.getPostData = async function (pid) { const posts = await Posts.getPostsFields([pid], []); return posts && posts.length ? posts[0] : null; }; - Posts.getPostsData = function (pids) { - return __awaiter(this, undefined, undefined, function* () { - return yield Posts.getPostsFields(pids, []); - }); + + Posts.getPostsData = async function (pids) { + return await Posts.getPostsFields(pids, []); }; - Posts.getPostField = function (pid, field) { - return __awaiter(this, undefined, undefined, function* () { - const post = yield Posts.getPostFields(pid, [field]); - return post ? post[field] : null; - }); + + Posts.getPostField = async function (pid, field) { + const post = await Posts.getPostFields(pid, [field]); + return post ? post[field] : null; }; - Posts.getPostFields = function (pid, fields) { - return __awaiter(this, undefined, undefined, function* () { - const posts = yield Posts.getPostsFields([pid], fields); - return posts ? posts[0] : null; - }); + + Posts.getPostFields = async function (pid, fields) { + const posts = await Posts.getPostsFields([pid], fields); + return posts ? posts[0] : null; }; - Posts.setPostField = function (pid, field, value) { - return __awaiter(this, undefined, undefined, function* () { - yield Posts.setPostFields(pid, { [field]: value }); - }); + + Posts.setPostField = async function (pid, field, value) { + await Posts.setPostFields(pid, { [field]: value }); }; - Posts.setPostFields = function (pid, data) { - return __awaiter(this, undefined, undefined, function* () { - yield db.setObject(`post:${pid}`, data); - plugins.hooks.fire('action:post.setFields', { data: { ...data, pid } }); - }); + + Posts.setPostFields = async function (pid, data) { + await db.setObject(`post:${pid}`, data); + plugins.hooks.fire('action:post.setFields', { data: { ...data, pid } }); }; }; @@ -92,4 +68,4 @@ function modifyPost(post, fields) { post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; } } -} +} \ No newline at end of file diff --git a/src/posts/data.ts b/src/posts/data.ts deleted file mode 100644 index 31802c219e..0000000000 --- a/src/posts/data.ts +++ /dev/null @@ -1,112 +0,0 @@ -import { getObjects, setObject, parseIntFields } from '../database'; -import { Hooks } from '../plugins/hooks'; -import { utils } from '../utils'; - -const intFields: string[] = [ - 'uid', 'pid', 'tid', 'deleted', 'timestamp', - 'upvotes', 'downvotes', 'deleterUid', 'edited', - 'replies', 'bookmarks', -]; - -interface Post { - votes: number; - upvotes: number; - downvotes: number; - timestamp: number; - timestampISO: string; - edited: number; - editedISO: string; -} - -interface Utils { - toISOString: (timestamp: number) => string; - } - -declare const utils:Utils; -declare const hooks:Hooks; -declare const getObjects: (keys: string[], fields: string[]) => Promise; - -function modifyPost(post:Post, fields:string[]): void { - if (post) { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - parseIntFields(post, intFields, fields); - if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { - post.votes = post.upvotes - post.downvotes; - } - if (post.hasOwnProperty('timestamp')) { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - post.timestampISO = utils.toISOString(post.timestamp); - } - if (post.hasOwnProperty('edited')) { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; - } - } -} - - - -export default class Posts { - static async getPostsFields(pids:string[], fields: string[]): Promise { - if (!Array.isArray(pids) || !pids.length) { - return []; - } - const keys = pids.map(pid => `post:${pid}`); - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - const postData: Post[] = await getObjects(keys, fields); - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line max-len - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment - const result: { pids: string[], posts: Post[], fields: string[] } = await hooks.fire('filter:post.getFields', { - pids: pids, - posts: postData, - fields: fields, - }); - result.posts.forEach((post: Post) => modifyPost(post, fields)); - return result.posts; - } - - static async getPostData(pid:string): Promise { - const posts:object[] = await Posts.getPostsFields([pid], []); - return posts && posts.length ? posts[0] : null; - } - - static async getPostsData(pids:string[]):Promise { - return await Posts.getPostsFields(pids, []); - } - - static async getPostFields(pid:string, fields:string[]): Promise { - const posts: object[] = await Posts.getPostsFields([pid], fields); - if (posts && posts.length) { - return posts[0]; - } - return null; - } - - static async getPostField(pid:string, field:string): Promise { - const post: object = await Posts.getPostFields(pid, [field]); - if (post) { - return post[field] as object; - } - return null; - } - - static async setPostField(pid:string, field:string, value:string):Promise { - await Posts.setPostFields(pid, { [field]: value }); - } - - static async setPostFields(pid:string, data:object): Promise { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - await setObject(`post:${pid}`, data); - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - Hooks.fire('action:post.setFields', { data: { ...data, pid } }); - } -} - - From 9d6a9f4e59db83a308872ce92793ebeb61ae084c Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Fri, 11 Oct 2024 22:34:00 -0400 Subject: [PATCH 08/15] Corrected new line required at end of file error --- src/posts/data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/posts/data.js b/src/posts/data.js index 9457778f66..3a4d303ff5 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -68,4 +68,4 @@ function modifyPost(post, fields) { post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; } } -} \ No newline at end of file +} From 7f3f8d24ddfeee204c834f6d64b85026744e936f Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Fri, 11 Oct 2024 22:48:14 -0400 Subject: [PATCH 09/15] Add src/posts/data.ts and its compiled js file --- src/posts/data.js | 159 +++++++++++++++++++++++++++++----------------- src/posts/data.ts | 110 ++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 60 deletions(-) create mode 100644 src/posts/data.ts diff --git a/src/posts/data.js b/src/posts/data.js index 2d87deb410..a9ad423f5a 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -1,70 +1,109 @@ -'use strict'; +"use strict"; -const db = require('../database'); -const plugins = require('../plugins'); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; + + +const database_1 = require("../database"); +const hooks = require("../plugins/hooks"); const utils = require('../utils'); const intFields = [ 'uid', 'pid', 'tid', 'deleted', 'timestamp', 'upvotes', 'downvotes', 'deleterUid', 'edited', 'replies', 'bookmarks', ]; - -module.exports = function (Posts) { - Posts.getPostsFields = async function (pids, fields) { - if (!Array.isArray(pids) || !pids.length) { - return []; - } - const keys = pids.map(pid => `post:${pid}`); - const postData = await db.getObjects(keys, fields); - const result = await plugins.hooks.fire('filter:post.getFields', { - pids: pids, - posts: postData, - fields: fields, - }); - result.posts.forEach(post => modifyPost(post, fields)); - return result.posts; - }; - - Posts.getPostData = async function (pid) { - const posts = await Posts.getPostsFields([pid], []); - return posts && posts.length ? posts[0] : null; - }; - - Posts.getPostsData = async function (pids) { - return await Posts.getPostsFields(pids, []); - }; - - Posts.getPostField = async function (pid, field) { - const post = await Posts.getPostFields(pid, [field]); - return post ? post[field] : null; - }; - - Posts.getPostFields = async function (pid, fields) { - const posts = await Posts.getPostsFields([pid], fields); - return posts ? posts[0] : null; - }; - - Posts.setPostField = async function (pid, field, value) { - await Posts.setPostFields(pid, { [field]: value }); - }; - - Posts.setPostFields = async function (pid, data) { - await db.setObject(`post:${pid}`, data); - plugins.hooks.fire('action:post.setFields', { data: { ...data, pid } }); - }; +function modifyPost(post, fields) { + if (post) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + (0, database_1.parseIntFields)(post, intFields, fields); + if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { + post.votes = post.upvotes - post.downvotes; + } + if (post.hasOwnProperty('timestamp')) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + post.timestampISO = utils.toISOString(post.timestamp); + } + if (post.hasOwnProperty('edited')) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; + } + } }; -function modifyPost(post, fields) { - if (post) { - db.parseIntFields(post, intFields, fields); - if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { - post.votes = post.upvotes - post.downvotes; - } - if (post.hasOwnProperty('timestamp')) { - post.timestampISO = utils.toISOString(post.timestamp); - } - if (post.hasOwnProperty('edited')) { - post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; - } - } +module.exports = function (Posts){ + Posts.getPostsFields = async function(pids, fields) { + return __awaiter(this, void 0, void 0, function* () { + if (!Array.isArray(pids) || !pids.length) { + return []; + } + const keys = pids.map(pid => `post:${pid}`); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + const postData = yield database_1.getObjects(keys, fields); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + const result = yield hooks.fire('filter:post.getFields', { + pids: pids, + posts: postData, + fields: fields, + }); + result.posts.forEach((post) => modifyPost(post, fields)); + return result.posts; + }); + }; + Posts.getPostData = async function(pid) { + return __awaiter(this, void 0, void 0, function* () { + const posts = yield Posts.getPostsFields([pid], []); + return posts && posts.length ? posts[0] : null; + }); + }; + Posts.getPostsData = async function(pids) { + return __awaiter(this, void 0, void 0, function* () { + return yield Posts.getPostsFields(pids, []); + }); + }; + Posts.getPostFields = async function(pid, fields) { + return __awaiter(this, void 0, void 0, function* () { + const posts = yield Posts.getPostsFields([pid], fields); + if (posts && posts.length) { + return posts[0]; + } + return null; + }); + }; + Posts.getPostField = async function(pid, field) { + return __awaiter(this, void 0, void 0, function* () { + const post = yield Posts.getPostFields(pid, [field]); + if (post) { + return post[field]; + } + return null; + }); + }; + Posts.setPostField = async function(pid, field, value) { + return __awaiter(this, void 0, void 0, function* () { + yield Posts.setPostFields(pid, { [field]: value }); + }); + }; + Posts.setPostFields = async function(pid, data) { + return __awaiter(this, void 0, void 0, function* () { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + yield (0, database_1.setObject)(`post:${pid}`, data); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + hooks.fire('action:post.setFields', { data: Object.assign(Object.assign({}, data), { pid }) }); + }); + }; } diff --git a/src/posts/data.ts b/src/posts/data.ts new file mode 100644 index 0000000000..e45a74f0ac --- /dev/null +++ b/src/posts/data.ts @@ -0,0 +1,110 @@ +import { getObjects, setObject, parseIntFields } from '../database'; +import { Hooks } from '../plugins/hooks'; +import { utils } from '../utils'; + +const intFields: string[] = [ + 'uid', 'pid', 'tid', 'deleted', 'timestamp', + 'upvotes', 'downvotes', 'deleterUid', 'edited', + 'replies', 'bookmarks', +]; + +interface Post { + votes: number; + upvotes: number; + downvotes: number; + timestamp: number; + timestampISO: string; + edited: number; + editedISO: string; +} + +interface Utils { + toISOString: (timestamp: number) => string; + } + +declare const utils:Utils; +declare const hooks:Hooks; +declare const getObjects: (keys: string[], fields: string[]) => Promise; + +function modifyPost(post:Post, fields:string[]): void { + if (post) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + parseIntFields(post, intFields, fields); + if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) { + post.votes = post.upvotes - post.downvotes; + } + if (post.hasOwnProperty('timestamp')) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + post.timestampISO = utils.toISOString(post.timestamp); + } + if (post.hasOwnProperty('edited')) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; + } + } +} + +export default class Posts { + static async getPostsFields(pids:string[], fields: string[]): Promise { + if (!Array.isArray(pids) || !pids.length) { + return []; + } + const keys = pids.map(pid => `post:${pid}`); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + const postData: Post[] = await getObjects(keys, fields); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + const result: { pids: string[], posts: Post[], fields: string[] } = await hooks.fire('filter:post.getFields', { + pids: pids, + posts: postData, + fields: fields, + }); + result.posts.forEach((post: Post) => modifyPost(post, fields)); + return result.posts; + } + + static async getPostData(pid:string): Promise { + const posts:object[] = await Posts.getPostsFields([pid], []); + return posts && posts.length ? posts[0] : null; + } + + static async getPostsData(pids:string[]):Promise { + return await Posts.getPostsFields(pids, []); + } + + static async getPostFields(pid:string, fields:string[]): Promise { + const posts: object[] = await Posts.getPostsFields([pid], fields); + if (posts && posts.length) { + return posts[0]; + } + return null; + } + + static async getPostField(pid:string, field:string): Promise { + const post: object = await Posts.getPostFields(pid, [field]); + if (post) { + return post[field] as object; + } + return null; + } + + static async setPostField(pid:string, field:string, value:string):Promise { + await Posts.setPostFields(pid, { [field]: value }); + } + + static async setPostFields(pid:string, data:object): Promise { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + await setObject(`post:${pid}`, data); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + Hooks.fire('action:post.setFields', { data: { ...data, pid } }); + } +} + + From 9901f1c8d4e43f527219414b4fc1e9f4b33920e3 Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Fri, 11 Oct 2024 23:19:01 -0400 Subject: [PATCH 10/15] Changing the class name in data.ts to see if it prevents git actions error --- src/posts/data.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/posts/data.ts b/src/posts/data.ts index e45a74f0ac..76026738cc 100644 --- a/src/posts/data.ts +++ b/src/posts/data.ts @@ -47,7 +47,7 @@ function modifyPost(post:Post, fields:string[]): void { } } -export default class Posts { +export default class Postss { static async getPostsFields(pids:string[], fields: string[]): Promise { if (!Array.isArray(pids) || !pids.length) { return []; @@ -69,16 +69,16 @@ export default class Posts { } static async getPostData(pid:string): Promise { - const posts:object[] = await Posts.getPostsFields([pid], []); + const posts:object[] = await Postss.getPostsFields([pid], []); return posts && posts.length ? posts[0] : null; } static async getPostsData(pids:string[]):Promise { - return await Posts.getPostsFields(pids, []); + return await Postss.getPostsFields(pids, []); } static async getPostFields(pid:string, fields:string[]): Promise { - const posts: object[] = await Posts.getPostsFields([pid], fields); + const posts: object[] = await Postss.getPostsFields([pid], fields); if (posts && posts.length) { return posts[0]; } @@ -86,7 +86,7 @@ export default class Posts { } static async getPostField(pid:string, field:string): Promise { - const post: object = await Posts.getPostFields(pid, [field]); + const post: object = await Postss.getPostFields(pid, [field]); if (post) { return post[field] as object; } @@ -94,7 +94,7 @@ export default class Posts { } static async setPostField(pid:string, field:string, value:string):Promise { - await Posts.setPostFields(pid, { [field]: value }); + await Postss.setPostFields(pid, { [field]: value }); } static async setPostFields(pid:string, data:object): Promise { From 45336d359e33f75f245dc7fb442face7c1c36287 Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Sat, 12 Oct 2024 00:42:28 -0400 Subject: [PATCH 11/15] fixed data.js to Typescrip translation --- src/posts/data.js | 46 ++++++++++++++-------------- src/posts/data.ts | 76 +++++++++++++++++++++++++---------------------- 2 files changed, 63 insertions(+), 59 deletions(-) diff --git a/src/posts/data.js b/src/posts/data.js index a9ad423f5a..db2b52108c 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -1,5 +1,4 @@ "use strict"; - var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -9,11 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; - - const database_1 = require("../database"); -const hooks = require("../plugins/hooks"); -const utils = require('../utils'); +const plugins_1 = require("../plugins"); +const utils_1 = require("../utils"); const intFields = [ 'uid', 'pid', 'tid', 'deleted', 'timestamp', 'upvotes', 'downvotes', 'deleterUid', 'edited', @@ -29,31 +26,31 @@ function modifyPost(post, fields) { } if (post.hasOwnProperty('timestamp')) { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - post.timestampISO = utils.toISOString(post.timestamp); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + post.timestampISO = (0, utils_1.toISOString)(post.timestamp); } if (post.hasOwnProperty('edited')) { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + post.editedISO = post.edited !== 0 ? (0, utils_1.toISOString)(post.edited) : ''; } } -}; - -module.exports = function (Posts){ - Posts.getPostsFields = async function(pids, fields) { +} +function toExport(Posts) { + Posts.getPostsFields = function (pids, fields) { return __awaiter(this, void 0, void 0, function* () { if (!Array.isArray(pids) || !pids.length) { return []; } const keys = pids.map(pid => `post:${pid}`); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - const postData = yield database_1.getObjects(keys, fields); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + const postData = yield (0, database_1.getObjects)(keys, fields); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS // eslint-disable-next-line max-len // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment - const result = yield hooks.fire('filter:post.getFields', { + const result = yield plugins_1.hooks.fire('filter:post.getFields', { pids: pids, posts: postData, fields: fields, @@ -62,18 +59,18 @@ module.exports = function (Posts){ return result.posts; }); }; - Posts.getPostData = async function(pid) { + Posts.getPostData = function (pid) { return __awaiter(this, void 0, void 0, function* () { const posts = yield Posts.getPostsFields([pid], []); return posts && posts.length ? posts[0] : null; }); }; - Posts.getPostsData = async function(pids) { + Posts.getPostsData = function (pids) { return __awaiter(this, void 0, void 0, function* () { return yield Posts.getPostsFields(pids, []); }); }; - Posts.getPostFields = async function(pid, fields) { + Posts.getPostFields = function (pid, fields) { return __awaiter(this, void 0, void 0, function* () { const posts = yield Posts.getPostsFields([pid], fields); if (posts && posts.length) { @@ -82,7 +79,7 @@ module.exports = function (Posts){ return null; }); }; - Posts.getPostField = async function(pid, field) { + Posts.getPostField = function (pid, field) { return __awaiter(this, void 0, void 0, function* () { const post = yield Posts.getPostFields(pid, [field]); if (post) { @@ -91,19 +88,20 @@ module.exports = function (Posts){ return null; }); }; - Posts.setPostField = async function(pid, field, value) { + Posts.setPostField = function (pid, field, value) { return __awaiter(this, void 0, void 0, function* () { yield Posts.setPostFields(pid, { [field]: value }); }); }; - Posts.setPostFields = async function(pid, data) { + Posts.setPostFields = function (pid, data) { return __awaiter(this, void 0, void 0, function* () { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + // eslint-disable-next-line @typescript-eslint/no-unsafe-call yield (0, database_1.setObject)(`post:${pid}`, data); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - hooks.fire('action:post.setFields', { data: Object.assign(Object.assign({}, data), { pid }) }); + plugins_1.hooks.fire('action:post.setFields', { data: Object.assign(Object.assign({}, data), { pid }) }); }); }; } +module.exports = toExport; diff --git a/src/posts/data.ts b/src/posts/data.ts index 76026738cc..d14f425089 100644 --- a/src/posts/data.ts +++ b/src/posts/data.ts @@ -1,6 +1,6 @@ import { getObjects, setObject, parseIntFields } from '../database'; -import { Hooks } from '../plugins/hooks'; -import { utils } from '../utils'; +import { hooks } from '../plugins'; +import { toISOString } from '../utils'; const intFields: string[] = [ 'uid', 'pid', 'tid', 'deleted', 'timestamp', @@ -18,13 +18,16 @@ interface Post { editedISO: string; } -interface Utils { - toISOString: (timestamp: number) => string; - } +interface Posts { + getPostsFields: (pids:string[], fields: string[]) => Promise + getPostData: (pid:string) => Promise + getPostsData: (pids:string[]) => Promise + getPostFields: (pid:string, fields:string[]) => Promise + getPostField: (pid:string, field:string) => Promise + setPostField: (pid:string, field:string, value:string) => Promise + setPostFields: (pid:string, data:object) => Promise +} -declare const utils:Utils; -declare const hooks:Hooks; -declare const getObjects: (keys: string[], fields: string[]) => Promise; function modifyPost(post:Post, fields:string[]): void { if (post) { @@ -36,25 +39,26 @@ function modifyPost(post:Post, fields:string[]): void { } if (post.hasOwnProperty('timestamp')) { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - post.timestampISO = utils.toISOString(post.timestamp); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + post.timestampISO = toISOString(post.timestamp); } if (post.hasOwnProperty('edited')) { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - post.editedISO = post.edited !== 0 ? utils.toISOString(post.edited) : ''; + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + post.editedISO = post.edited !== 0 ? toISOString(post.edited) : ''; } } } -export default class Postss { - static async getPostsFields(pids:string[], fields: string[]): Promise { +function toExport(Posts:Posts):void { + Posts.getPostsFields = async function (pids:string[], fields: string[]): Promise { if (!Array.isArray(pids) || !pids.length) { return []; } const keys = pids.map(pid => `post:${pid}`); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment const postData: Post[] = await getObjects(keys, fields); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS // eslint-disable-next-line max-len @@ -66,45 +70,47 @@ export default class Postss { }); result.posts.forEach((post: Post) => modifyPost(post, fields)); return result.posts; - } + }; - static async getPostData(pid:string): Promise { - const posts:object[] = await Postss.getPostsFields([pid], []); + Posts.getPostData = async function (pid:string): Promise { + const posts:object[] = await Posts.getPostsFields([pid], []); return posts && posts.length ? posts[0] : null; - } + }; - static async getPostsData(pids:string[]):Promise { - return await Postss.getPostsFields(pids, []); - } + Posts.getPostsData = async function (pids:string[]):Promise { + return await Posts.getPostsFields(pids, []); + }; - static async getPostFields(pid:string, fields:string[]): Promise { - const posts: object[] = await Postss.getPostsFields([pid], fields); + Posts.getPostFields = async function (pid:string, fields:string[]): Promise { + const posts: object[] = await Posts.getPostsFields([pid], fields); if (posts && posts.length) { return posts[0]; } return null; - } + }; - static async getPostField(pid:string, field:string): Promise { - const post: object = await Postss.getPostFields(pid, [field]); + Posts.getPostField = async function (pid:string, field:string): Promise { + const post: object = await Posts.getPostFields(pid, [field]); if (post) { return post[field] as object; } return null; - } + }; - static async setPostField(pid:string, field:string, value:string):Promise { - await Postss.setPostFields(pid, { [field]: value }); - } + Posts.setPostField = async function (pid:string, field:string, value:string):Promise { + await Posts.setPostFields(pid, { [field]: value }); + }; - static async setPostFields(pid:string, data:object): Promise { + Posts.setPostFields = async function (pid:string, data:object): Promise { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + // eslint-disable-next-line @typescript-eslint/no-unsafe-call await setObject(`post:${pid}`, data); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - Hooks.fire('action:post.setFields', { data: { ...data, pid } }); - } + hooks.fire('action:post.setFields', { data: { ...data, pid } }); + }; } +export = toExport + From a4df038d1f6b61a620c0c819e647eb839b7f8e1f Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Sat, 12 Oct 2024 01:06:47 -0400 Subject: [PATCH 12/15] Added the command await to async call --- src/posts/data.js | 2 +- src/posts/data.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/posts/data.js b/src/posts/data.js index db2b52108c..1c430c637f 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -100,7 +100,7 @@ function toExport(Posts) { yield (0, database_1.setObject)(`post:${pid}`, data); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - plugins_1.hooks.fire('action:post.setFields', { data: Object.assign(Object.assign({}, data), { pid }) }); + yield plugins_1.hooks.fire('action:post.setFields', { data: Object.assign(Object.assign({}, data), { pid }) }); }); }; } diff --git a/src/posts/data.ts b/src/posts/data.ts index d14f425089..ef8a482e7b 100644 --- a/src/posts/data.ts +++ b/src/posts/data.ts @@ -78,7 +78,7 @@ function toExport(Posts:Posts):void { }; Posts.getPostsData = async function (pids:string[]):Promise { - return await Posts.getPostsFields(pids, []); + return await Posts.getPostsFields(pids, []) }; Posts.getPostFields = async function (pid:string, fields:string[]): Promise { @@ -107,7 +107,7 @@ function toExport(Posts:Posts):void { await setObject(`post:${pid}`, data); // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - hooks.fire('action:post.setFields', { data: { ...data, pid } }); + await hooks.fire('action:post.setFields', { data: { ...data, pid } }); }; } From 79edde026270a9f70a4ec084ea9fcfa5b94692bf Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Sat, 12 Oct 2024 01:09:40 -0400 Subject: [PATCH 13/15] Adds missing semicolon --- src/posts/data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/posts/data.ts b/src/posts/data.ts index ef8a482e7b..3ba02240c4 100644 --- a/src/posts/data.ts +++ b/src/posts/data.ts @@ -78,7 +78,7 @@ function toExport(Posts:Posts):void { }; Posts.getPostsData = async function (pids:string[]):Promise { - return await Posts.getPostsFields(pids, []) + return await Posts.getPostsFields(pids, []); }; Posts.getPostFields = async function (pid:string, fields:string[]): Promise { From 06f68564c462293778aefb1ecbb60d1e9adfaca3 Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Sat, 12 Oct 2024 12:50:23 -0400 Subject: [PATCH 14/15] Changed the target in tsconfig,json to allow the use of async/await, added type in data.ts --- src/posts/data.js | 109 ++++++++++++++++++---------------------------- src/posts/data.ts | 2 +- tsconfig.json | 2 +- 3 files changed, 45 insertions(+), 68 deletions(-) diff --git a/src/posts/data.js b/src/posts/data.js index 1c430c637f..ce71c6b4ce 100644 --- a/src/posts/data.js +++ b/src/posts/data.js @@ -1,13 +1,4 @@ "use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; const database_1 = require("../database"); const plugins_1 = require("../plugins"); const utils_1 = require("../utils"); @@ -38,70 +29,56 @@ function modifyPost(post, fields) { } } function toExport(Posts) { - Posts.getPostsFields = function (pids, fields) { - return __awaiter(this, void 0, void 0, function* () { - if (!Array.isArray(pids) || !pids.length) { - return []; - } - const keys = pids.map(pid => `post:${pid}`); - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment - const postData = yield (0, database_1.getObjects)(keys, fields); - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line max-len - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment - const result = yield plugins_1.hooks.fire('filter:post.getFields', { - pids: pids, - posts: postData, - fields: fields, - }); - result.posts.forEach((post) => modifyPost(post, fields)); - return result.posts; + Posts.getPostsFields = async function (pids, fields) { + if (!Array.isArray(pids) || !pids.length) { + return []; + } + const keys = pids.map(pid => `post:${pid}`); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + const postData = await (0, database_1.getObjects)(keys, fields); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line max-len + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment + const result = await plugins_1.hooks.fire('filter:post.getFields', { + pids: pids, + posts: postData, + fields: fields, }); + result.posts.forEach((post) => modifyPost(post, fields)); + return result.posts; }; - Posts.getPostData = function (pid) { - return __awaiter(this, void 0, void 0, function* () { - const posts = yield Posts.getPostsFields([pid], []); - return posts && posts.length ? posts[0] : null; - }); + Posts.getPostData = async function (pid) { + const posts = await Posts.getPostsFields([pid], []); + return posts && posts.length ? posts[0] : null; }; - Posts.getPostsData = function (pids) { - return __awaiter(this, void 0, void 0, function* () { - return yield Posts.getPostsFields(pids, []); - }); + Posts.getPostsData = async function (pids) { + return await Posts.getPostsFields(pids, []); }; - Posts.getPostFields = function (pid, fields) { - return __awaiter(this, void 0, void 0, function* () { - const posts = yield Posts.getPostsFields([pid], fields); - if (posts && posts.length) { - return posts[0]; - } - return null; - }); + Posts.getPostFields = async function (pid, fields) { + const posts = await Posts.getPostsFields([pid], fields); + if (posts && posts.length) { + return posts[0]; + } + return null; }; - Posts.getPostField = function (pid, field) { - return __awaiter(this, void 0, void 0, function* () { - const post = yield Posts.getPostFields(pid, [field]); - if (post) { - return post[field]; - } - return null; - }); + Posts.getPostField = async function (pid, field) { + const post = await Posts.getPostFields(pid, [field]); + if (post) { + return post[field]; + } + return null; }; - Posts.setPostField = function (pid, field, value) { - return __awaiter(this, void 0, void 0, function* () { - yield Posts.setPostFields(pid, { [field]: value }); - }); + Posts.setPostField = async function (pid, field, value) { + await Posts.setPostFields(pid, { [field]: value }); }; - Posts.setPostFields = function (pid, data) { - return __awaiter(this, void 0, void 0, function* () { - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - yield (0, database_1.setObject)(`post:${pid}`, data); - // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - yield plugins_1.hooks.fire('action:post.setFields', { data: Object.assign(Object.assign({}, data), { pid }) }); - }); + Posts.setPostFields = async function (pid, data) { + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + await (0, database_1.setObject)(`post:${pid}`, data); + // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call + await plugins_1.hooks.fire('action:post.setFields', { data: Object.assign(Object.assign({}, data), { pid }) }); }; } module.exports = toExport; diff --git a/src/posts/data.ts b/src/posts/data.ts index 3ba02240c4..12e2b7b78c 100644 --- a/src/posts/data.ts +++ b/src/posts/data.ts @@ -72,7 +72,7 @@ function toExport(Posts:Posts):void { return result.posts; }; - Posts.getPostData = async function (pid:string): Promise { + Posts.getPostData = async function (pid:string): Promise { const posts:object[] = await Posts.getPostsFields([pid], []); return posts && posts.length ? posts[0] : null; }; diff --git a/tsconfig.json b/tsconfig.json index 10aeeef7e6..c15cb37711 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "allowJs": false, - "target": "es6", + "target": "es2017", "module": "commonjs", "moduleResolution": "node", "esModuleInterop": true, From a03f1ae70c9e7c4d2068d7d66776318f01ef30fc Mon Sep 17 00:00:00 2001 From: andreaDimartin <18-10826@usb.ve> Date: Sat, 12 Oct 2024 13:26:30 -0400 Subject: [PATCH 15/15] Removed unnecesary comment line --- src/posts/data.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/posts/data.ts b/src/posts/data.ts index 12e2b7b78c..90e37f2ba6 100644 --- a/src/posts/data.ts +++ b/src/posts/data.ts @@ -44,7 +44,6 @@ function modifyPost(post:Post, fields:string[]): void { } if (post.hasOwnProperty('edited')) { // La siguiente línea llama a una función en un módulo que aún no ha sido actualizado a TS - // eslint-disable-next-line max-len // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment post.editedISO = post.edited !== 0 ? toISOString(post.edited) : ''; }