mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Export user likes
This commit is contained in:
parent
09b2eed63d
commit
1626b49c37
@ -8,6 +8,7 @@ import { Action } from "../helpers/APILimitsHelper";
|
||||
import { UserController } from "./UserController";
|
||||
import { PostsController } from "./PostsController";
|
||||
import { CommentsController } from "./CommentsController";
|
||||
import { LikesController } from "./LikesController";
|
||||
|
||||
/**
|
||||
* Account controller
|
||||
@ -237,6 +238,9 @@ export class AccountController {
|
||||
|
||||
// User comments
|
||||
comments: await CommentsController.CommentsToAPI(h, data.comments),
|
||||
|
||||
// User likes
|
||||
likes: data.likes.map(LikesController.UserLikeToAPI)
|
||||
};
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { LikesType, LikesHelper } from "../helpers/LikesHelper";
|
||||
import { UserHelper } from "../helpers/UserHelper";
|
||||
import { GroupsAccessLevel } from "../entities/Group";
|
||||
import { UserLike } from "../entities/UserLike";
|
||||
|
||||
/**
|
||||
* Likes controller
|
||||
@ -74,4 +75,18 @@ export class LikesController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a user like entry into an API entry
|
||||
*
|
||||
* @param l The like entry
|
||||
*/
|
||||
public static UserLikeToAPI(l: UserLike) : any {
|
||||
return {
|
||||
id: l.id,
|
||||
userID: l.userID,
|
||||
time_sent: l.timeSent,
|
||||
elem_type: l.elemType,
|
||||
elem_id: l.elemId
|
||||
}
|
||||
}
|
||||
}
|
@ -7,12 +7,14 @@
|
||||
import { User } from "./User";
|
||||
import { Post } from "./Post";
|
||||
import { Comment } from "./Comment";
|
||||
import { UserLike } from "./UserLike";
|
||||
|
||||
export interface AccountExportBuilder {
|
||||
userID: number;
|
||||
userInfo: User;
|
||||
postsList: Post[];
|
||||
comments: Comment[];
|
||||
likes: UserLike[];
|
||||
}
|
||||
|
||||
export class AccountExport implements AccountExportBuilder {
|
||||
@ -20,6 +22,7 @@ export class AccountExport implements AccountExportBuilder {
|
||||
userInfo: User;
|
||||
postsList: Post[];
|
||||
comments: Comment[];
|
||||
likes: UserLike[];
|
||||
|
||||
public constructor(info: AccountExportBuilder) {
|
||||
for (const key in info) {
|
||||
|
28
src/entities/UserLike.ts
Normal file
28
src/entities/UserLike.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* User like
|
||||
*
|
||||
* @author Pierre Hubert
|
||||
*/
|
||||
|
||||
export interface UserLikeBuilder {
|
||||
id: number,
|
||||
userID: number,
|
||||
timeSent: number,
|
||||
elemType: string,
|
||||
elemId: string
|
||||
}
|
||||
|
||||
export class UserLike implements UserLikeBuilder {
|
||||
id: number;
|
||||
userID: number;
|
||||
timeSent: number;
|
||||
elemType: string;
|
||||
elemId: string;
|
||||
|
||||
public constructor(info: UserLikeBuilder) {
|
||||
for (const key in info) {
|
||||
if (info.hasOwnProperty(key))
|
||||
this[key] = info[key];
|
||||
}
|
||||
}
|
||||
}
|
@ -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),
|
||||
})
|
||||
|
||||
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user