Skip to content

Commit 1197cfc

Browse files
committed
Use REST and GraphQL
1 parent 8ec3d12 commit 1197cfc

13 files changed

Lines changed: 222 additions & 14 deletions

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"express": "^4.17.1",
3030
"graphql": "^14.4.2",
3131
"http": "0.0.0",
32+
"lodash": "^4.17.15",
3233
"ncp": "^2.0.0"
3334
},
3435
"devDependencies": {

src/_data/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
init() {},
3+
}

src/_data/notificationsData.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const notificationsData = {}
2+
3+
export default notificationsData

src/_data/organizationsData.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Organization from '_types/Organization'
2+
import organizationsToUsersData from './organizationsToUsersData'
3+
4+
console.log('organizationsToUsersData', organizationsToUsersData)
5+
6+
const organizationsDataById: { [key: number]: Organization } = {
7+
1: {
8+
id: 1,
9+
name: 'ModularCode',
10+
plan: {
11+
id: 'silver',
12+
name: 'Silver',
13+
},
14+
// organizationToUsers: organizationsToUsersData.byOrganizationId[1],
15+
},
16+
2: {
17+
id: 2,
18+
name: 'Cool LLC',
19+
plan: {
20+
id: 'gold',
21+
name: 'Gold',
22+
},
23+
// organizationToUsers: organizationsToUsersData.byOrganizationId[2],
24+
},
25+
3: {
26+
id: 3,
27+
name: 'Other LLC',
28+
plan: {
29+
id: 'trial',
30+
name: 'Trial',
31+
},
32+
// organizationToUsers: organizationsToUsersData.byOrganizationId[3],
33+
},
34+
}
35+
36+
const organizationsData = {
37+
byId: organizationsDataById,
38+
}
39+
40+
export default organizationsData
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import _groupBy from 'lodash/groupBy'
2+
import OrganizationToUser from '_types/OrganizationToUser'
3+
4+
// import organizationsData from './organizationsData'
5+
// import usersData from './usersData'
6+
7+
const list: OrganizationToUser[] = [
8+
{
9+
id: 1,
10+
organizationId: 1,
11+
userId: 1,
12+
role: 'owner',
13+
// organization: organizationsData.byId[1],
14+
// user: usersData.byId[1],
15+
},
16+
{
17+
id: 2,
18+
organizationId: 1,
19+
userId: 2,
20+
role: 'admin',
21+
// organization: organizationsData.byId[1],
22+
// user: usersData.byId[2],
23+
},
24+
{
25+
id: 3,
26+
organizationId: 1,
27+
userId: 2,
28+
role: 'member',
29+
// organization: organizationsData.byId[1],
30+
// user: usersData.byId[2],
31+
},
32+
{
33+
id: 4,
34+
organizationId: 2,
35+
userId: 2,
36+
role: 'owner',
37+
// organization: organizationsData.byId[2],
38+
// user: usersData.byId[2],
39+
},
40+
{
41+
id: 5,
42+
organizationId: 3,
43+
userId: 3,
44+
role: 'owner',
45+
// organization: organizationsData.byId[3],
46+
// user: usersData.byId[3],
47+
},
48+
{
49+
id: 6,
50+
organizationId: 3,
51+
userId: 2,
52+
role: 'member',
53+
// organization: organizationsData.byId[3],
54+
// user: usersData.byId[2],
55+
},
56+
]
57+
58+
const byUserId = _groupBy(list, 'userId')
59+
const byOrganizationId = _groupBy(list, 'organizationId')
60+
61+
console.log('byOrganizationId', byOrganizationId)
62+
63+
export default {
64+
list,
65+
byUserId,
66+
byOrganizationId,
67+
}

src/_data/usersData.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import _keyBy from 'lodash/keyBy'
2+
import User from '_types/User'
3+
import organizationsToUsersData from './organizationsToUsersData'
4+
5+
const list: User[] = [
6+
{
7+
id: 1,
8+
firstName: 'John',
9+
lastName: 'Doe',
10+
username: 'johndoe1',
11+
email: 'john@doe.com',
12+
avatarUrl: 'https://avatars3.githubusercontent.com/u/3959008?v=3&s=40',
13+
userToOrganizations: organizationsToUsersData.byUserId[1],
14+
globalRole: 'admin',
15+
},
16+
{
17+
id: 2,
18+
firstName: 'Jay',
19+
lastName: 'Nickolson',
20+
username: null,
21+
email: 'example@gmail.com',
22+
avatarUrl:
23+
'https://tinyfac.es/data/avatars/475605E3-69C5-4D2B-8727-61B7BB8C4699-500w.jpeg',
24+
userToOrganizations: organizationsToUsersData.byUserId[2],
25+
},
26+
{
27+
id: 3,
28+
firstName: 'Ana',
29+
lastName: 'De Armas',
30+
username: null,
31+
email: 'Ana+De+Armas@example.com',
32+
avatarUrl:
33+
'https://images-na.ssl-images-amazon.com/images/M/MV5BMjA3NjYzMzE1MV5BMl5BanBnXkFtZTgwNTA4NDY4OTE@._V1_UX172_CR0,0,172,256_AL_.jpg',
34+
userToOrganizations: organizationsToUsersData.byUserId[3],
35+
},
36+
{
37+
id: 4,
38+
firstName: 'Armas',
39+
lastName: 'De Ana',
40+
username: null,
41+
email: 'Ana+De+Armas@example.com',
42+
avatarUrl:
43+
'https://images-na.ssl-images-amazon.com/images/M/MV5BMjA3NjYzMzE1MV5BMl5BanBnXkFtZTgwNTA4NDY4OTE@._V1_UX172_CR0,0,172,256_AL_.jpg',
44+
userToOrganizations: organizationsToUsersData.byUserId[4],
45+
},
46+
{
47+
id: 5,
48+
firstName: 'Sonequa',
49+
lastName: 'Martin-Green',
50+
email: 'Sonequa+Martin+Green@example.com',
51+
avatarUrl:
52+
'https://images-na.ssl-images-amazon.com/images/M/MV5BMTgxMTc1MTYzM15BMl5BanBnXkFtZTgwNzI5NjMwOTE@._V1_UY256_CR16,0,172,256_AL_.jpg',
53+
userToOrganizations: organizationsToUsersData.byUserId[5],
54+
},
55+
]
56+
57+
const byId: { [key: number]: User } = _keyBy(list, 'id')
58+
59+
const usersData = {
60+
list,
61+
byId,
62+
current: byId[1],
63+
}
64+
65+
export default usersData

src/api/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import express from 'express'
2+
import { Application } from 'express'
3+
4+
export default {
5+
init(path: string, app: Application) {
6+
// get an instance of router
7+
const router = express.Router()
8+
9+
router.get('/', (req, res) => {
10+
res.send('Hello REST api!')
11+
})
12+
13+
app.use(path, router)
14+
},
15+
}

src/apiGraphQL/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Application } from 'express'
2+
import { ApolloServer } from 'apollo-server-express'
3+
import depthLimit from 'graphql-depth-limit'
4+
5+
import schema from './schema'
6+
7+
const server = new ApolloServer({
8+
schema,
9+
validationRules: [depthLimit(7)],
10+
})
11+
12+
export default {
13+
init(path: string, app: Application) {
14+
server.applyMiddleware({ app, path })
15+
},
16+
}

0 commit comments

Comments
 (0)