1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 00:25:17 +00:00

Export user likes

This commit is contained in:
2020-03-25 19:08:43 +01:00
parent 09b2eed63d
commit 1626b49c37
6 changed files with 85 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import { GeneralSettings, UserPageStatus, LangSettings, SecuritySettings } from
import { AccountExport } from "../entities/AccountExport";
import { PostsHelper } from "./PostsHelper";
import { CommentsHelper } from "./CommentsHelper";
import { LikesHelper } from "./LikesHelper";
/**
* Account helper
@ -393,7 +394,10 @@ export class AccountHelper {
postsList: await PostsHelper.ExportAllPostsUser(userID),
// Export the list of comments
comments: await CommentsHelper.ExportAllUser(userID)
comments: await CommentsHelper.ExportAllUser(userID),
// Export user likes
likes: await LikesHelper.ExportAllUser(userID),
})

View File

@ -1,5 +1,6 @@
import { DatabaseHelper } from "./DatabaseHelper";
import { mysql_date } from "../utils/DateUtils";
import { UserLike } from "../entities/UserLike";
/**
* Likes helper
@ -119,4 +120,33 @@ export class LikesHelper {
type: LikesKindsDB[type]
});
}
/**
* Get all the likes of a user
*
* @param userID Target user ID
*/
public static async ExportAllUser(userID: number) {
return (await DatabaseHelper.Query({
table: LIKES_TABLE,
where: {
ID_personne: userID
}
})).map(this.DBToUserLike);
}
/**
* Turn a database entry into a like entry
*
* @param row Target database row
*/
private static DBToUserLike(row: any) : UserLike {
return new UserLike({
id: row.ID,
userID: row.ID_personne,
timeSent: new Date(row.Date_envoi).getTime()/1000,
elemId: row.ID_type,
elemType: row.type
})
}
}