|
|
@ -137,8 +137,12 @@ export class Post extends Model<Post> {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public async userVote({userId}: {userId: number}, request: any): Promise<VoteType> {
|
|
|
|
public async userVote({userId}: {userId: number}, request: any): Promise<VoteType> {
|
|
|
|
userId = userId ?? request.session.userId;
|
|
|
|
userId = userId ?? request.session.userId;
|
|
|
|
|
|
|
|
if (userId) {
|
|
|
|
const votes = await this.$get("rVotes", {where: {id: userId}}) as Array<User & {PostVote: PostVote}>;
|
|
|
|
const votes = await this.$get("rVotes", {where: {id: userId}}) as Array<User & {PostVote: PostVote}>;
|
|
|
|
return votes[0]?.PostVote?.voteType;
|
|
|
|
return votes[0]?.PostVote?.voteType;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -149,7 +153,7 @@ export class Post extends Model<Post> {
|
|
|
|
public async deletable({userId}: {userId: number}, request: any): Promise<boolean> {
|
|
|
|
public async deletable({userId}: {userId: number}, request: any): Promise<boolean> {
|
|
|
|
userId = userId ?? request.session.userId;
|
|
|
|
userId = userId ?? request.session.userId;
|
|
|
|
const isAuthor = Number(userId) === Number(this.authorId);
|
|
|
|
const isAuthor = Number(userId) === Number(this.authorId);
|
|
|
|
if (!isAuthor) {
|
|
|
|
if (userId && !isAuthor) {
|
|
|
|
return (await User.findOne({where: {id: userId}})).isAdmin;
|
|
|
|
return (await User.findOne({where: {id: userId}})).isAdmin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isAuthor;
|
|
|
|
return isAuthor;
|
|
|
|