Skip to content
Permalink
Browse files
First Commit
  • Loading branch information
Wilson committed Jul 29, 2019
0 parents commit 3070409f472981b81e6a90fe6156a180fc7f51be
Show file tree
Hide file tree
Showing 35 changed files with 9,657 additions and 0 deletions.
@@ -0,0 +1,75 @@

{
"env": {
"es6": true,
"jasmine": true,
"node": true,
"browser": true,
"jest": true
},
"parserOptions": {
"ecmaVersion": 8
},
"rules": {
"arrow-body-style": 2,
"arrow-parens": ["error", "as-needed"],
"arrow-spacing": ["warn", {"before": true, "after": true}],
"brace-style": 2,
"camelcase": [2, {"properties": "never"}],
"complexity": ["warn", 4],
"eol-last": "warn",
"eqeqeq": "error",
"func-call-spacing": ["error", "never"],
"global-require": "error",
"handle-callback-err": "warn",
"indent": [1, "tab", {"SwitchCase": 1}],
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
"linebreak-style": ["warn", "unix"],
"max-depth": ["warn", 3],
"max-len": ["warn", { "code": 120, "tabWidth": 4 }],
"max-lines": ["warn", 100],
"max-lines-per-function": ["warn", 15],
"max-nested-callbacks": ["warn", 4],
"max-params": ["warn", 5],
"max-statements": ["warn", 10],
"no-cond-assign": 2,
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": "warn",
"no-empty-function": 2,
"no-multiple-empty-lines": "warn",
"no-extra-parens": 2,
"no-func-assign": 2,
"no-irregular-whitespace": 2,
"no-magic-numbers": [1, {"ignore": [-1, 0, 1]}],
"no-multi-spaces": 1,
"no-multi-str": 1,
"no-unexpected-multiline": 2,
"no-unreachable": 2,
"no-self-assign": 2,
"no-trailing-spaces": 1,
"no-undef": 2,
"no-unused-vars": 1,
"no-var": 2,
"prefer-arrow-callback": 1,
"prefer-const": 2,
"prefer-template": "error",
"quotes": [1, "single"],
"semi": [1, "never"],
"space-before-blocks": ["error", { "functions": "always", "keywords": "always", "classes": "never" }],
"space-before-function-paren": [2, "never"],
"strict": [2, "global"],
"yoda": 2
},
"overrides": [{
"files": [ "*.test.js", "*.spec.js", "sqlite-async.js" ],
"rules": {
"global-require": "off",
"max-lines-per-function": "off",
"max-lines": "off",
"max-statements": "off",
"no-magic-numbers": "off"
}
}]
}
@@ -0,0 +1,5 @@

.DS_Store
node_modules/
*.db
screenshots/*
@@ -0,0 +1,8 @@
# Assignment Template

This repository contains the base files for the assignment. To make use of this carry out the following steps:

1. Fork this repository but change its name (replace `xxx` with your university username):
1. If this is your original assignment, `xxx-coursework`.
2. If this is your resit assignment code, `xxx-resit`.
2. Replace the contents of this file with the details of the topic you have been assigned.
@@ -0,0 +1,51 @@

'use strict'

const records = [
{
id: 0,
user: 'jdoe',
pass: '$2b$10$vPqO/uGlKchrQCqyBIKdb.8hLEJgaC4aAg4fpre5rausycX1XmkWy'
}
]

module.exports.open = function() {
return {
all: async sql => {
console.log(`MOCK ${sql}`)
let field = sql.match(/(?<=SELECT\s+).*?(?=\s+FROM)/g)[0]
const condition = sql.match(/\bWHERE\s+(.*)$/g)[0].replace('WHERE ', '').replace(';', '')
const key = condition.split('=')[0].trim()
const val = condition.split('=')[1].replace(/"/g, '').trim()
console.log(`field: "${field}", condition: "${condition}", key: "${key}", val: "${val}"`)
if(field === 'count(id) AS count') field = 'id'
console.log(`field: "${field}"`)
let data = []
console.log(`${field} : ${key} : ${val}`)
for(const record of records) {
//console.log(record)
console.log(record[field])
console.log(`"${record[field]}" : "${val}"`)
if(record[field] == val) {
console.log('matching record')
data.push(record)
}
}
console.log(data)
let result = {}
console.log(`field ${field} length: ${field.length}`)
if(field === 'id') {
console.log('need count...')
result.count = data.length
} else {
console.log('need data...')
result[field] = records[0][field]
}
console.log(result)
return result
},
run: async() => true, // we can just ignore these.
close: async() => true // pretend to close the database.
}
}

@@ -0,0 +1,22 @@

'use strict'

const sqlite = require('sqlite-async')

module.exports.open = function() {
return {
all: async sql => {
console.log(`MOCK ${sql}`)
const db = await sqlite.open(':memory:')
await db.run('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, pass TEXT);')
const user = 'jdoe'
const pass = '$2b$10$vPqO/uGlKchrQCqyBIKdb.8hLEJgaC4aAg4fpre5rausycX1XmkWy'
await db.run(`INSERT INTO URLSearchParams(user, pass) VALUES("${user}", "${pass}");`)
const data = await db.all(sql)
await db.close()
return data
},
run: async() => true, // we can just ignore these.
close: async() => true // pretend to close the database.
}
}

0 comments on commit 3070409

Please sign in to comment.