Update updateRequestScore endpoint and clean up naming
parent
54a7145630
commit
36d3871bdc
|
@ -1,7 +1,7 @@
|
|||
CREATE TABLE scores (
|
||||
url varchar,
|
||||
baseScore int NOT NULL DEFAULT 0,
|
||||
score int NOT NULL DEFAULT 0,
|
||||
scoreModifier int NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (url),
|
||||
FOREIGN KEY (url) REFERENCES requests(url)
|
||||
);
|
||||
|
|
|
@ -32,7 +32,7 @@ case of no votes), and users.is{follower,subscriber} must be COALESCEd to FALSE
|
|||
as in the case of no votes, user.* will be NULL.
|
||||
*/
|
||||
|
||||
CREATE OR REPLACE VIEW vote_score_all_vw AS
|
||||
CREATE OR REPLACE VIEW vote_score_vw AS
|
||||
WITH votepoints AS (SELECT normaluservotepoints, followervotepoints, subscribervotepoints FROM config)
|
||||
SELECT requests.url AS url,
|
||||
COUNT(votes.requesturl) AS count,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
CREATE OR REPLACE PROCEDURE update_scores()
|
||||
LANGUAGE SQL
|
||||
AS $$
|
||||
UPDATE scores SET score = basescore + votescore
|
||||
FROM vote_score_all_vw
|
||||
WHERE scores.url = vote_score_all_vw.url;
|
||||
UPDATE scores SET score = votescore + scoreModifier
|
||||
FROM vote_score_vw
|
||||
WHERE scores.url = vote_score_vw.url;
|
||||
$$;
|
||||
|
||||
CREATE OR REPLACE PROCEDURE add_request(url varchar,requester int)
|
||||
|
@ -28,3 +28,10 @@ CREATE OR REPLACE PROCEDURE delete_vote(url varchar,voteuser int)
|
|||
DELETE FROM votes WHERE requesturl = url AND userid = voteuser;
|
||||
CALL update_scores();
|
||||
$$;
|
||||
|
||||
CREATE OR REPLACE PROCEDURE update_request_score_modifier(updateurl varchar, scoreDiff int)
|
||||
LANGUAGE SQL
|
||||
AS $$
|
||||
UPDATE scores SET scoreModifier = scoreModifier + scoreDiff WHERE url = updateurl;
|
||||
CALL update_scores();
|
||||
$$;
|
||||
|
|
|
@ -128,7 +128,7 @@ app.post("/api/updateRequestState", async (request, response) => {
|
|||
.catch((e: any) => errorHandler(request,response,e));
|
||||
});
|
||||
|
||||
app.post("/api/updateRequestScore", async (request, response) => {
|
||||
app.post("/api/updateRequestScoreModifier", async (request, response) => {
|
||||
if (request.session) await validateApiToken(request.session);
|
||||
if (!request.session || !request.session.user) {
|
||||
response.status(401);
|
||||
|
@ -154,7 +154,7 @@ app.post("/api/updateRequestScore", async (request, response) => {
|
|||
var url = request.body.url as string;
|
||||
var scoreDiff = parseInt(request.body.scoreDiff as string, 10);
|
||||
response.type('text/plain');
|
||||
requests.updateRequestScore(url,scoreDiff).then((val: [number,string]) => {
|
||||
requests.updateRequestScoreModifier(url,scoreDiff).then((val: [number,string]) => {
|
||||
response.status(val[0]);
|
||||
response.send(val[1]);
|
||||
})
|
||||
|
|
|
@ -82,9 +82,9 @@ export const updateRequestState = {
|
|||
text: "UPDATE requests SET state = $2 WHERE url = $1"
|
||||
}
|
||||
|
||||
export const updateRequestScore = {
|
||||
name: "updateRequestScore",
|
||||
text: "UPDATE requests SET score = score + $2 WHERE url = $1"
|
||||
export const updateRequestScoreModifier = {
|
||||
name: "updateRequestScoreModifier",
|
||||
text: "CALL update_request_score_modifier($1,$2)"
|
||||
}
|
||||
|
||||
export const deleteRequest = {
|
||||
|
|
|
@ -61,8 +61,8 @@ export async function updateRequestState(url: string, state: string): Promise<[n
|
|||
.then(() => [200,"Song request state updated."] as [number,string]);
|
||||
};
|
||||
|
||||
export async function updateRequestScore(url: string, scoreDiff: number): Promise<[number,string]> {
|
||||
var query = Object.assign(queries.updateRequestScore, { values: [url,scoreDiff] });
|
||||
export async function updateRequestScoreModifier(url: string, scoreDiff: number): Promise<[number,string]> {
|
||||
var query = Object.assign(queries.updateRequestScoreModifier, { values: [url,scoreDiff] });
|
||||
return db.query(query)
|
||||
.then(() => [200,"Song request score updated."] as [number,string]);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue