Skip to content
This repository was archived by the owner on Sep 19, 2019. It is now read-only.

Commit

Permalink
Added approver relation
Browse files Browse the repository at this point in the history
  • Loading branch information
7imbrook committed Feb 8, 2016
1 parent d440f33 commit c479f57
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 16 deletions.
9 changes: 9 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM iron/node:4.2-dev

WORKDIR /app
COPY ./ /app

RUN npm install
RUN npm run build

CMD /bin/bash -c "exit 0;"
14 changes: 9 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ gateway:
ports:
- "80:80"
volumes:
- "./app/dist:/usr/share/nginx/html"
- ./app/dist:/usr/share/nginx/html
links:
- pgapi
- server

pgapi:
build: ./services/postgrest
dockerfile: Dockerfile.interface
restart: always
links:
- db
ports:
- "9999:3000"

db:
build: ./services/postgrest
Expand All @@ -29,5 +30,8 @@ db:

server:
build: ./server
ports:
- "8080:3000"

static:
build: ./app
volumes:
- statics:/src/dist
15 changes: 9 additions & 6 deletions server/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ const pool = pg.Pool('postgres://admin:alpine@192.168.99.100/projects');
module.exports = {
createRequest (r) {

let approverid = 1;

return pool.query(sql`
WITH approval AS (
INSERT INTO approval_status(approved_by) VALUES (${approverid}) RETURNING id
) INSERT INTO public.requests(project, requester, part, unit_price, quantity, link, purpose, approval)
WITH
approvers AS (
SELECT approver_id as id FROM defaultapprovers WHERE project_id=${r.project} LIMIT 1
),
approval AS (
INSERT INTO approval_status(approved_by) VALUES ((select id from approvers)) RETURNING id
) INSERT INTO requests(project, requester, part, unit_price, quantity, link, purpose, approval)
VALUES (${r.project}, 1, ${r.part}, ${r.unit_price}, ${r.quantity}, ${r.link}, ${r.purpose}, (select id from approval))
RETURNING id;
`)
Expand All @@ -23,10 +25,11 @@ module.exports = {
})
.catch(err => {
if (err.message.indexOf("requests_project_fkey") > 0) {
let err = new Error("Project does not exist")
let err = new Error("Project does not exist");
err.status = 412;
throw err;
}
throw err;
});
}
}
10 changes: 5 additions & 5 deletions services/nginx/conf/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ server {
root /usr/share/nginx/html;

location /r/ {
# limit_except GET OPTIONS {
# deny all;
# }
# TODO: link to actual backends
proxy_pass http://192.168.99.100:9999/;
proxy_pass http://pgapi:3000/;
}

location /s/ {
proxy_pass http://server:3000/;
}

}
13 changes: 13 additions & 0 deletions services/postgrest/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ CREATE TABLE projects
created date NOT NULL default CURRENT_DATE
);

CREATE TABLE public.account_manager_for_project
(
projectid integer,
accountid integer,
id serial PRIMARY KEY,
CONSTRAINT account_manager_for_project_accountid_fkey FOREIGN KEY (accountid)
REFERENCES public.accounts (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT account_manager_for_project_projectid_fkey FOREIGN KEY (projectid)
REFERENCES public.projects (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);

CREATE TABLE approval_status
(
id serial PRIMARY KEY,
Expand Down
10 changes: 10 additions & 0 deletions services/postgrest/scratch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
WITH
approvers AS (
SELECT approver_id as id FROM defaultapprovers WHERE project_id=1
),
approval AS (
INSERT INTO approval_status(approved_by) VALUES ((select id from approvers)) RETURNING id
)
INSERT INTO requests(project, requester, part, unit_price, quantity, link, purpose, approval)
VALUES (1, 1, "Part", 0.01, 5, "http://google.com", "Blah Blah", (select id from approval))
RETURNING id;
10 changes: 10 additions & 0 deletions services/postgrest/views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ select
left join purchase on requests.purchase=purchase.id
;

CREATE VIEW defaultapprovers AS
select
accounts.id as approver_id,
projects.id as project_id
from account_manager_for_project
join accounts on
accounts.id=account_manager_for_project.accountid
join projects on
projects.id=account_manager_for_project.projectid
;
COMMIT;

0 comments on commit c479f57

Please sign in to comment.