Skip to content

Commit

Permalink
deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
crookse committed Oct 29, 2020
1 parent 23002f3 commit f015bba
Show file tree
Hide file tree
Showing 25 changed files with 645 additions and 523 deletions.
3 changes: 1 addition & 2 deletions src/a.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import { hash, compare } from "https://deno.land/x/bcrypt@v0.2.2/mod.ts";

import { compare, hash } from "https://deno.land/x/bcrypt@v0.2.2/mod.ts";
146 changes: 79 additions & 67 deletions src/models/article_comments_model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import BaseModel from "./base_model.ts";
import {ArticleModel} from "./article_model.ts";
import { ArticleModel } from "./article_model.ts";

export type ArticleCommentEntity = {
created_at: number;
id: number;
article_id: number
body: string
article_id: number;
body: string;
updated_at: number;
author_id: number;
author_image: string
author_username: string
author_image: string;
author_username: string;
};

export type Filters = {
Expand All @@ -25,16 +25,18 @@ export type Filters = {
*
* @return ArticleModel
*/
export function createArticleCommentsModelObject(article: ArticleCommentEntity): ArticleCommentsModel {
export function createArticleCommentsModelObject(
article: ArticleCommentEntity,
): ArticleCommentsModel {
return new ArticleCommentsModel(
article.article_id,
article.body,
article.author_image,
article.author_id,
article.author_username,
article.created_at,
article.updated_at,
article.id
article.article_id,
article.body,
article.author_image,
article.author_id,
article.author_username,
article.created_at,
article.updated_at,
article.id,
);
}

Expand Down Expand Up @@ -85,7 +87,7 @@ export class ArticleCommentsModel extends BaseModel {
*/
public author_username: string;

public author_image: string
public author_image: string;

/**
* @var number
Expand All @@ -94,7 +96,7 @@ export class ArticleCommentsModel extends BaseModel {
*/
public updated_at: number;

public slug: string
public slug: string;

//////////////////////////////////////////////////////////////////////////////
// FILE MARKER - CONSTRCUTOR /////////////////////////////////////////////////
Expand All @@ -110,26 +112,28 @@ export class ArticleCommentsModel extends BaseModel {
* @param number updatedAt=Date
*/
constructor(
articleId: number,
body: string,
authorImage: string,
authorId: number,
authorUsername: string,
createdAt: number = Date.now(),
updatedAt: number = Date.now(),
id: number = -1,
slug: string = ""
articleId: number,
body: string,
authorImage: string,
authorId: number,
authorUsername: string,
createdAt: number = Date.now(),
updatedAt: number = Date.now(),
id: number = -1,
slug: string = "",
) {
super();
this.id = id;
this.article_id = articleId;
this.body = body;
this.author_id = authorId
this.author_image = authorImage
this.author_username = authorUsername
this.author_id = authorId;
this.author_image = authorImage;
this.author_username = authorUsername;
this.created_at = createdAt;
this.updated_at = updatedAt;
this.slug = this.id == -1 ? this.createSlug(this.author_id + this.body + this.author_username) : slug;
this.slug = this.id == -1
? this.createSlug(this.author_id + this.body + this.author_username)
: slug;
}

//////////////////////////////////////////////////////////////////////////////
Expand All @@ -144,10 +148,10 @@ export class ArticleCommentsModel extends BaseModel {
public async delete(): Promise<boolean> {
let query = `DELETE FROM article_comments WHERE id = ?`;
query = this.prepareQuery(
query,
[
String(this.id),
],
query,
[
String(this.id),
],
);

try {
Expand All @@ -173,19 +177,19 @@ export class ArticleCommentsModel extends BaseModel {
// }

let query = "INSERT INTO article_comments " +
" (article_id, author_image, author_id, author_username, body, created_at, updated_at)" +
" VALUES (?, ?, ?, ?, ?, to_timestamp(?), to_timestamp(?));";
" (article_id, author_image, author_id, author_username, body, created_at, updated_at)" +
" VALUES (?, ?, ?, ?, ?, to_timestamp(?), to_timestamp(?));";
query = this.prepareQuery(
query,
[
String(this.article_id),
this.author_image,
this.author_id,
this.author_username,
this.body,
String(Date.now() / 1000.00),
String(Date.now() / 1000.00),
],
query,
[
String(this.article_id),
this.author_image,
this.author_id,
this.author_username,
this.body,
String(Date.now() / 1000.00),
String(Date.now() / 1000.00),
],
);

const client = await BaseModel.connect();
Expand All @@ -194,8 +198,10 @@ export class ArticleCommentsModel extends BaseModel {

// @ts-ignore
// (crookse) We ignore this because this will never return null.
const tmp = await ArticleCommentsModel.where({ author_id: this.author_id, body: this.body });
return tmp[0]
const tmp = await ArticleCommentsModel.where(
{ author_id: this.author_id, body: this.body },
);
return tmp[0];
}

/**
Expand Down Expand Up @@ -250,10 +256,10 @@ export class ArticleCommentsModel extends BaseModel {
client.release();

let results = BaseModel.formatResults(
dbResult.rows,
dbResult.rowDescription.columns,
dbResult.rows,
dbResult.rowDescription.columns,
);
return ArticleCommentsModel.constructArticleComments(results)
return ArticleCommentsModel.constructArticleComments(results);
}

/**
Expand All @@ -265,15 +271,15 @@ export class ArticleCommentsModel extends BaseModel {
* @return Promise<ArticleModel[]|[]>
*/
static async where(
fields: any,
fields: any,
): Promise<ArticleCommentsModel[] | []> {
let results = await BaseModel.Where("article_comments", fields);

if (results.length <= 0) {
return [];
}

return ArticleCommentsModel.constructArticleComments(results)
return ArticleCommentsModel.constructArticleComments(results);
}

/**
Expand All @@ -286,8 +292,8 @@ export class ArticleCommentsModel extends BaseModel {
* @return Promise<ArticleModel[]|[]>
*/
static async whereIn(
column: string,
values: any,
column: string,
values: any,
): Promise<ArticleCommentsModel[] | []> {
let results = await BaseModel.WhereIn("article_comments", {
column,
Expand All @@ -298,7 +304,7 @@ export class ArticleCommentsModel extends BaseModel {
return [];
}

return ArticleCommentsModel.constructArticleComments(results)
return ArticleCommentsModel.constructArticleComments(results);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -334,27 +340,33 @@ export class ArticleCommentsModel extends BaseModel {
*/
protected createSlug(title: string): string {
return title.toLowerCase()
.replace(/[^a-zA-Z0-9 ]/g, "")
.replace(/\s/g, "-");
.replace(/[^a-zA-Z0-9 ]/g, "")
.replace(/\s/g, "-");
}

protected static constructArticleComments (results: Array<{ [key: string]: string | number | boolean }>): Array<ArticleCommentsModel>|[] {
protected static constructArticleComments(
results: Array<{ [key: string]: string | number | boolean }>,
): Array<ArticleCommentsModel> | [] {
const articleComments: Array<ArticleCommentsModel> = [];
results.forEach((result) => {
const entity: ArticleCommentEntity = {
id: typeof result.id === "number" ? result.id : 0,
body: typeof result.body === "string" ? result.body : "",
author_id: typeof result.author_id === "number" ? result.author_id : 0,
created_at: typeof result.created_at === "number"
? result.created_at
: 0,
updated_at: typeof result.updated_at === "number" ? result.updated_at
: 0,
article_id: typeof result.article_id === "number"
? result.article_id
: 0,
author_username: typeof result.author_username === "string" ? result.author_username : "",
author_image: typeof result.author_image === "string" ? result.author_image : ""
? result.created_at
: 0,
updated_at: typeof result.updated_at === "number"
? result.updated_at
: 0,
article_id: typeof result.article_id === "number" ? result.article_id
: 0,
author_username: typeof result.author_username === "string"
? result.author_username
: "",
author_image: typeof result.author_image === "string"
? result.author_image
: "",
};
articleComments.push(createArticleCommentsModelObject(entity));
});
Expand Down
10 changes: 5 additions & 5 deletions src/models/article_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ArticleEntity = {
slug?: string;
title: string;
updated_at: number;
tags?: string
tags?: string;
};

export type Filters = {
Expand Down Expand Up @@ -261,7 +261,7 @@ export class ArticleModel extends BaseModel {
this.description,
this.body,
String(Date.now()),
this.tags
this.tags,
],
);
const client = await BaseModel.connect();
Expand Down Expand Up @@ -335,7 +335,7 @@ export class ArticleModel extends BaseModel {
updated_at: typeof result.updated_at === "number" ? result.updated_at
: 0,
tags: typeof result.tags === "string" ? result.tags : "",
slug: typeof result.slug === "string" ? result.slug : ""
slug: typeof result.slug === "string" ? result.slug : "",
};
articles.push(createArticleModelObject(entity));
});
Expand Down Expand Up @@ -381,7 +381,7 @@ export class ArticleModel extends BaseModel {
updated_at: typeof result.updated_at === "number" ? result.updated_at
: 0,
tags: typeof result.tags === "string" ? result.tags : "",
slug: typeof result.slug === "string" ? result.slug : ""
slug: typeof result.slug === "string" ? result.slug : "",
};
articles.push(createArticleModelObject(entity));
});
Expand Down Expand Up @@ -432,7 +432,7 @@ export class ArticleModel extends BaseModel {
updated_at: typeof result.updated_at === "number" ? result.updated_at
: 0,
tags: typeof result.tags === "string" ? result.tags : "",
slug: typeof result.slug === "string" ? result.slug : ""
slug: typeof result.slug === "string" ? result.slug : "",
};
articles.push(createArticleModelObject(entity));
});
Expand Down
4 changes: 2 additions & 2 deletions src/models/base_model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pool, PoolClient, QueryResult, Column } from "../deps.ts";
import { Column, Pool, PoolClient, QueryResult } from "../deps.ts";

export const dbPool = new Pool({
user: "user",
Expand Down Expand Up @@ -162,7 +162,7 @@ export default abstract class BaseModel {
* @return string
* The query with the placeholders replaced with the data
*/
protected prepareQuery(query: string, data?: Array<string|number>): string {
protected prepareQuery(query: string, data?: Array<string | number>): string {
if (!data || !data.length) {
return query;
}
Expand Down
13 changes: 5 additions & 8 deletions src/public/js/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ const router = new VueRouter({
// Ensure we checked auth before each page load.
router.beforeEach(async (to, from, next) => {
if (to.path !== "/login" && to.path !== "/register" && to.path !== "/") {
const result = await store.dispatch("checkIfUserIsAuthenticated")
const result = await store.dispatch("checkIfUserIsAuthenticated");
if (!result) {
router.push("/login")
router.push("/login");
}
next()
next();
} else {
next()
next();
}
});

Expand All @@ -175,7 +175,4 @@ window.app = new Vue({
},
});

export {
store,
router,
};
export { router, store };
Loading

0 comments on commit f015bba

Please sign in to comment.