This repository was archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Assignment8 #6
Open
CryptoKage2306
wants to merge
5
commits into
master
Choose a base branch
from
assignment8
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Assignment8 #6
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c3dff1e
DB insert only functionality created
quode-doc a564996
Bug Fixes in Sales index
quode-doc 3b9b210
Migrations are implemented
quode-doc 115b532
added git ignore remove all node modules from tree
quode-doc ae69150
Indent Correction
quode-doc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules/ | ||
| Untitled-1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "development": { | ||
| "username": "postgres", | ||
| "password":"test123", | ||
| "database": "test", | ||
| "host": "127.0.0.1", | ||
| "dialect": "postgres" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <html> | ||
|
|
||
| <head> | ||
| <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> | ||
| <script> | ||
| $(document).ready(function () { | ||
| $("input[type='button']").click(function () { | ||
| var radioValue = $("input[name='type']:checked").val(); | ||
| if (radioValue == "text") { | ||
| var settings = { | ||
| "async": true, | ||
| "crossDomain": true, | ||
| "url": "http://localhost:3000/", | ||
| "method": "POST", | ||
| "headers": { | ||
| "Content-Type": "text/plain", | ||
| "cache-control": "no-cache", | ||
| }, | ||
| "data": document.getElementById('data').value | ||
| } | ||
|
|
||
| $.ajax(settings).done(function (response) { | ||
| let str=""; | ||
| for(let i of response.stmt){ | ||
| str+=i+"<br>" | ||
| } | ||
| document.getElementById('data1').innerHTML=`${response.name}<br>${str}Sales:${response.sales}<br>Total:${response.total}` | ||
| }); | ||
| } | ||
| else { | ||
| var settings = { | ||
| "async": true, | ||
| "crossDomain": true, | ||
| "url": "http://localhost:3000/", | ||
| "method": "POST", | ||
| "headers": { | ||
| "Content-Type": "application/json", | ||
| "cache-control": "no-cache", | ||
| }, | ||
| "data": document.getElementById('data').value | ||
| } | ||
|
|
||
| $.ajax(settings).done(function (response) { | ||
| let str=""; | ||
| for(let i of response.stmt){ | ||
| str+=i+"<br>" | ||
| } | ||
| document.getElementById('data1').innerHTML=`${response.name}<br>${str}Sales:${response.sales}<br>Total:${response.total}` | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| }); | ||
| </script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <input type="radio" name="type" value="json" />json | ||
| <input type="radio" name="type" value="text" />text | ||
| <input type="text" name="data" id="data"> | ||
| <input type="button" value="Get Value"> | ||
| <p id='data1'></p> | ||
|
|
||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| const express=require('express'); | ||
| const {insert}=require('./sequelizeorder'); | ||
| const Sequelize = require('sequelize'); | ||
| const bodyParser=require('body-parser') | ||
| const app = express(); | ||
| const tax = require('./sales_imported'); | ||
| const text_tax = require('./sales_imported_text'); | ||
| app.use("/", bodyParser.json()); | ||
| app.use("/", bodyParser.text()) | ||
| app.get("/", (req, res) =>{ | ||
| console.count('homepage'); | ||
| res.sendFile('/home/asd/myapp/index.html', (err) =>{ | ||
| if (err) { | ||
| console.log(err); | ||
| } | ||
| }); | ||
| }); | ||
| app.post('/', (req, res, next) =>{ | ||
| if (req.headers["content-type"] == "application/json") { | ||
| console.log(req.body); | ||
| var array = req.body.items; | ||
| var str = [] | ||
| let total = 0; | ||
| let sales = 0; | ||
| let reqtime=new Date().getTime(); | ||
| for (let item of array) { | ||
| str.push(`${item.quantity} ${tax.isimported(item)} ${item.name}: ${item.price + tax.salestax(item) + tax.importtax(item)}`); | ||
| sales += tax.salestax(item) + tax.importtax(item); | ||
| priceall=item.price + tax.salestax(item) + tax.importtax(item); | ||
| total += item.price + tax.salestax(item) + tax.importtax(item); | ||
| insert(req.body.name,item,priceall,tax.isimported(item)) | ||
| } | ||
| res.json({ | ||
| "name":req.body.name, | ||
| "stmt":str, | ||
| "total":total, | ||
| "sales":sales | ||
|
|
||
| }); | ||
| console.dir({ | ||
| "name":req.body.name, | ||
| "stmt":str, | ||
| "total":total, | ||
| "sales":sales | ||
|
|
||
| }) | ||
| let restime=new Date().getTime(); | ||
| res.end(); | ||
| } if (req.headers["content-type"] == "text/plain") { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same line? |
||
| next(); | ||
| } | ||
| }, (req, res) =>{ | ||
| let reqtime=new Date().getTime(); | ||
| let str = req.body; | ||
| orderNo = str.split(":"); | ||
| sentences = orderNo[1].split("\\n"); | ||
| quantity = []; | ||
| body = []; | ||
| price = []; | ||
| for (let i = 1; i < sentences.length; i++) { | ||
| regex = new RegExp('(\\d+)'); | ||
| temp = sentences[i].split(regex); | ||
| quantity.push(temp[1]); | ||
| lastind=temp[2].lastIndexOf("at"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh ugh |
||
| body.push(temp[2].substr(0,lastind)+":"); | ||
| price.push(temp[3]+temp[4]+temp[5]); | ||
| } | ||
| stmt=[]; | ||
| total=0; | ||
| sales=0 | ||
| for(let i=1;i<sentences.length;i++){ | ||
| sales+=text_tax.sales_tax(quantity[i-1],body[i-1],price[i-1])+text_tax.imported_tax(quantity[i-1],body[i-1],price[i-1]); | ||
| aftertax=parseFloat(price[i-1])+text_tax.sales_tax(quantity[i-1],body[i-1],price[i-1])+text_tax.imported_tax(quantity[i-1],body[i-1],price[i-1]); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not just a murder. This is genocide! |
||
| stmt.push(`${quantity[i-1]} ${body[i-1]} ${aftertax}`); | ||
| total+=aftertax; | ||
| console.log(body[i-1].split(':')) | ||
| item={ | ||
| 'name':body[i-1].split(':')[0], | ||
| 'category':text_tax.category(body[i-1]), | ||
| 'quantity':quantity[i-1] | ||
| } | ||
| insert(orderNo[0],item,aftertax,text_tax.imported_category(body[i-1])) | ||
| } | ||
| res.json({ | ||
| "name":orderNo[0], | ||
| "stmt":stmt, | ||
| "total":total, | ||
| "sales":sales | ||
| }); | ||
| let restime=new Date().getTime(); | ||
| res.end("hello"); | ||
| }); | ||
| app.listen(3000); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 'use strict'; | ||
| module.exports = { | ||
| up: (queryInterface, Sequelize) => { | ||
| return queryInterface.createTable('orders', { | ||
| id: { | ||
| allowNull: false, | ||
| autoIncrement: true, | ||
| primaryKey: true, | ||
| type: Sequelize.INTEGER | ||
| }, | ||
| orderName: { | ||
| type: Sequelize.STRING | ||
| }, | ||
| createdAt: { | ||
| allowNull: false, | ||
| type: Sequelize.DATE | ||
| }, | ||
| updatedAt: { | ||
| allowNull: false, | ||
| type: Sequelize.DATE | ||
| } | ||
| }); | ||
| }, | ||
| down: (queryInterface, Sequelize) => { | ||
| return queryInterface.dropTable('orders'); | ||
| } | ||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EOF? |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| up: (queryInterface, Sequelize) => { | ||
| return Promise.all( | ||
| [ | ||
| queryInterface.addColumn('orders', 'itemName', { | ||
| type: Sequelize.STRING, | ||
| allowNull: false | ||
| }), | ||
| queryInterface.addColumn('orders', 'itemCategory', { | ||
| type: Sequelize.STRING, | ||
| allowNull: false | ||
| }), | ||
| queryInterface.addColumn('orders', 'quantity', { | ||
| type: Sequelize.INTEGER, | ||
| allowNull: false | ||
| }), | ||
| queryInterface.addColumn('orders', 'price', { | ||
| type: Sequelize.FLOAT, | ||
| allowNull: false | ||
| }), | ||
| queryInterface.addColumn('orders', 'imported', { | ||
| type: Sequelize.STRING, | ||
| allowNull: true | ||
| }) | ||
| ] | ||
| ) | ||
| }, | ||
|
|
||
| down: (queryInterface, Sequelize) => { | ||
| return Promise.all( | ||
| [ | ||
| queryInterface.removeColumn('orders', 'itemName'), | ||
| queryInterface.removeColumn('orders', 'itemCategory'), | ||
| queryInterface.removeColumn('orders', 'quantity'), | ||
| queryInterface.removeColumn('orders', 'price'), | ||
| queryInterface.removeColumn('orders', 'imported') | ||
| ] | ||
| ) | ||
| /* | ||
| Add reverting commands here. | ||
| Return a promise to correctly handle asynchronicity. ,. | ||
|
|
||
| Example: | ||
| return queryInterface.dropTable('users'); | ||
| */ | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const Sequelize = require('sequelize'); | ||
| const basename = path.basename(__filename); | ||
| const env = process.env.NODE_ENV || 'development'; | ||
| const config = require(__dirname + '/../config/config.json')[env]; | ||
| const db = {}; | ||
|
|
||
| let sequelize; | ||
| if (config.use_env_variable) { | ||
| sequelize = new Sequelize(process.env[config.use_env_variable], config); | ||
| } else { | ||
| sequelize = new Sequelize(config.database, config.username, config.password, config); | ||
| } | ||
|
|
||
| fs | ||
| .readdirSync(__dirname) | ||
| .filter(file => { | ||
| return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); | ||
| }) | ||
| .forEach(file => { | ||
| const model = sequelize['import'](path.join(__dirname, file)); | ||
| db[model.name] = model; | ||
| }); | ||
|
|
||
| Object.keys(db).forEach(modelName => { | ||
| if (db[modelName].associate) { | ||
| db[modelName].associate(db); | ||
| } | ||
| }); | ||
|
|
||
| db.sequelize = sequelize; | ||
| db.Sequelize = Sequelize; | ||
|
|
||
| module.exports = db; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 'use strict'; | ||
| module.exports = (sequelize, DataTypes) => { | ||
| const order = sequelize.define('order', { | ||
| orderName: DataTypes.STRING, | ||
| itemName: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false | ||
| }, | ||
| itemCategory: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false | ||
| }, | ||
| quantity: { | ||
| type: DataTypes.INTEGER, | ||
| allowNull: false | ||
| }, | ||
| price: { | ||
| type: DataTypes.FLOAT, | ||
| allowNull: false | ||
| }, | ||
| imported: { | ||
| type: DataTypes.STRING, | ||
| allowNull: true | ||
| }, | ||
| }, {}); | ||
| order.associate = function (models) { | ||
| // associations can be defined here | ||
| }; | ||
| return order; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting?