|
|
@ -16,6 +16,7 @@ export class Post extends DataObject {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public async upvotes(): Promise<number> {
|
|
|
|
public async upvotes(): Promise<number> {
|
|
|
|
const result = await queryHelper.first({
|
|
|
|
const result = await queryHelper.first({
|
|
|
|
|
|
|
|
cache: true,
|
|
|
|
text: "SELECT COUNT(*) count FROM votes WHERE item_id = $1 AND vote_type = 'UPVOTE'",
|
|
|
|
text: "SELECT COUNT(*) count FROM votes WHERE item_id = $1 AND vote_type = 'UPVOTE'",
|
|
|
|
values: [this.id],
|
|
|
|
values: [this.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -27,6 +28,7 @@ export class Post extends DataObject {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public async downvotes(): Promise<number> {
|
|
|
|
public async downvotes(): Promise<number> {
|
|
|
|
const result = await queryHelper.first({
|
|
|
|
const result = await queryHelper.first({
|
|
|
|
|
|
|
|
cache: true,
|
|
|
|
text: "SELECT COUNT(*) count FROM votes WHERE item_id = $1 AND vote_type = 'DOWNVOTE'",
|
|
|
|
text: "SELECT COUNT(*) count FROM votes WHERE item_id = $1 AND vote_type = 'DOWNVOTE'",
|
|
|
|
values: [this.id],
|
|
|
|
values: [this.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -80,6 +82,7 @@ export class Post extends DataObject {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public async userVote(userId: number): Promise<dataaccess.VoteType> {
|
|
|
|
public async userVote(userId: number): Promise<dataaccess.VoteType> {
|
|
|
|
const result = await queryHelper.first({
|
|
|
|
const result = await queryHelper.first({
|
|
|
|
|
|
|
|
cache: true,
|
|
|
|
text: "SELECT vote_type FROM votes WHERE user_id = $1 AND item_id = $2",
|
|
|
|
text: "SELECT vote_type FROM votes WHERE user_id = $1 AND item_id = $2",
|
|
|
|
values: [userId, this.id],
|
|
|
|
values: [userId, this.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -127,6 +130,7 @@ export class Post extends DataObject {
|
|
|
|
result = this.row;
|
|
|
|
result = this.row;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
result = await queryHelper.first({
|
|
|
|
result = await queryHelper.first({
|
|
|
|
|
|
|
|
cache: true,
|
|
|
|
text: "SELECT * FROM posts WHERE posts.id = $1",
|
|
|
|
text: "SELECT * FROM posts WHERE posts.id = $1",
|
|
|
|
values: [this.id],
|
|
|
|
values: [this.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
|