Skip to content

Commit

Permalink
v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
iamanishroy committed Jun 26, 2022
1 parent 61dcc4a commit 5ea0024
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 199 deletions.
202 changes: 101 additions & 101 deletions backend/controllers/like.js
Original file line number Diff line number Diff line change
@@ -1,112 +1,112 @@
require('dotenv').config;
const UrlParser = require('url-parse');
require("dotenv").config;
const UrlParser = require("url-parse");
const { StatusCodes, ReasonPhrases } = require("http-status-codes");
const { addLike, getLike, removeLike } = require('../models/like');
const { addLike, getLike, removeLike } = require("../models/like");
const { millify } = require("millify");

exports.addLike = async (req, res) => {
let origin;

if (req.headers['Pass-Origin']) {
origin = "https://page-like-test.dev";
} else {
origin = req.get('origin');
}
var _url = new UrlParser(origin);

if (!_url.host) {
return res.status(StatusCodes.BAD_REQUEST).send({
success: false,
code: 'BAD_REQUEST',
message: ReasonPhrases.BAD_REQUEST
});
}

const transaction = await addLike(_url.host);

if (!transaction) {
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
success: false,
code: 'INTERNAL_SERVER_ERROR',
message: ReasonPhrases.INTERNAL_SERVER_ERROR
});
}

return res.status(StatusCodes.ACCEPTED).send({
success: true,
message: ReasonPhrases.ACCEPTED,
totalLike: transaction.likeCount
let origin;

if (req.headers["Pass-Origin"]) {
origin = "https://page-like-test.dev";
} else {
origin = req.get("origin");
}
var _url = new UrlParser(origin);

if (!_url.host) {
return res.status(StatusCodes.BAD_REQUEST).send({
success: false,
code: "BAD_REQUEST",
message: ReasonPhrases.BAD_REQUEST,
});
};
}

const transaction = await addLike(_url.host);

if (!transaction) {
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
success: false,
code: "INTERNAL_SERVER_ERROR",
message: ReasonPhrases.INTERNAL_SERVER_ERROR,
});
}

return res.status(StatusCodes.ACCEPTED).send({
success: true,
message: ReasonPhrases.ACCEPTED,
totalLike: millify(transaction.likeCount),
});
};

exports.getLike = async (req, res) => {
let origin;

if (req.headers && req.headers['Pass-Origin']) {
origin = "https://page-like-test.dev";
} else {
origin = req.get('origin');
}
var _url = new UrlParser(origin);

if (!_url.host) {
return res.status(StatusCodes.BAD_REQUEST).send({
success: false,
code: 'BAD_REQUEST',
message: ReasonPhrases.BAD_REQUEST
});
}

const transaction = await getLike(_url.host);

if (!transaction) {
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
success: false,
code: 'INTERNAL_SERVER_ERROR',
message: ReasonPhrases.INTERNAL_SERVER_ERROR
});
}

return res.status(StatusCodes.OK).send({
success: true,
message: ReasonPhrases.OK,
totalLike: transaction.likeCount
let origin;

if (req.headers && req.headers["Pass-Origin"]) {
origin = "https://page-like-test.dev";
} else {
origin = req.get("origin");
}
var _url = new UrlParser(origin);

if (!_url.host) {
return res.status(StatusCodes.BAD_REQUEST).send({
success: false,
code: "BAD_REQUEST",
message: ReasonPhrases.BAD_REQUEST,
});
}

const transaction = await getLike(_url.host);

if (!transaction) {
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
success: false,
code: "INTERNAL_SERVER_ERROR",
message: ReasonPhrases.INTERNAL_SERVER_ERROR,
});
}
}

return res.status(StatusCodes.OK).send({
success: true,
message: ReasonPhrases.OK,
totalLike: millify(transaction.likeCount),
});
};

exports.removeLike = async (req, res) => {
let origin;

if (req.headers['Pass-Origin']) {
origin = "https://page-like-test.dev";
} else {
origin = req.get('origin');
}
var _url = new UrlParser(origin);

if (!_url.host) {
return res.status(StatusCodes.BAD_REQUEST).send({
success: false,
code: 'BAD_REQUEST',
message: ReasonPhrases.BAD_REQUEST
});
}

const [success, transaction] = await removeLike(_url.host);

if (!transaction) {
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
success: false,
code: 'INTERNAL_SERVER_ERROR',
message: ReasonPhrases.INTERNAL_SERVER_ERROR
});
}

return res.status(
success ? StatusCodes.ACCEPTED : StatusCodes.CONFLICT
).send({
success: success,
message: success ? ReasonPhrases.ACCEPTED : ReasonPhrases.CONFLICT,
totalLike: transaction.likeCount
let origin;

if (req.headers["Pass-Origin"]) {
origin = "https://page-like-test.dev";
} else {
origin = req.get("origin");
}
var _url = new UrlParser(origin);

if (!_url.host) {
return res.status(StatusCodes.BAD_REQUEST).send({
success: false,
code: "BAD_REQUEST",
message: ReasonPhrases.BAD_REQUEST,
});
};
}

const [success, transaction] = await removeLike(_url.host);

if (!transaction) {
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
success: false,
code: "INTERNAL_SERVER_ERROR",
message: ReasonPhrases.INTERNAL_SERVER_ERROR,
});
}

return res
.status(success ? StatusCodes.ACCEPTED : StatusCodes.CONFLICT)
.send({
success: success,
message: success ? ReasonPhrases.ACCEPTED : ReasonPhrases.CONFLICT,
totalLike: millify(transaction.likeCount),
});
};
Loading

1 comment on commit 5ea0024

@vercel
Copy link

@vercel vercel bot commented on 5ea0024 Jun 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pagelike – ./

pagelike.vercel.app
pagelike-git-main-anishroy.vercel.app
pagelike-anishroy.vercel.app

Please sign in to comment.