Skip to content

Commit 873cea9

Browse files
committed
add sorting menu in nav bar
1 parent bd0dbfa commit 873cea9

File tree

7 files changed

+20
-5
lines changed

7 files changed

+20
-5
lines changed

__tests__/projects.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
const app = require('../server/server');
12
const request = require('supertest');
23
let server = 'https://reactype.herokuapp.com';
34
const isDev = process.env.NODE_ENV === 'development';
45
if (isDev) {
56
// server = 'http://localhost:5000';
6-
server = require('./server');
7+
server = require('..server/server');
78
}
89

910
// save and get projects endpoint testing
10-
describe('Project endpoints tests', () => {
11+
describe('Project GraphQL endpoints tests', () => {
1112
// initializes the project to be sent to server/DB
1213
const state = {
1314
name: 'test',
@@ -42,7 +43,7 @@ describe('Project endpoints tests', () => {
4243
.send(projectToSave)
4344
.expect('Content-Type', /json/)
4445
.expect(200)
45-
.then((res) => expect(res.body.project.name).toBe('test'));
46+
.then(res => expect(res.body.project.name).toBe('test'));
4647
});
4748
});
4849
});
@@ -74,7 +75,7 @@ describe('Project endpoints tests', () => {
7475
.send({ name, userId })
7576
.expect(200)
7677
.expect('Content-Type', /json/)
77-
.then((res) => expect(res.body.name).toBe('test'));
78+
.then(res => expect(res.body.name).toBe('test'));
7879
});
7980
});
8081
});

app/src/Dashboard/ProjectContainer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ const ProjectContainer = () => {
3535

3636
const sortByDate = (projects) => {
3737
console.log('sort by date', projects);
38-
// not sure how to sort by dates
38+
39+
const sortedRatings = projects.sort((a, b) => b.createdAt - a.createdAt);
40+
console.log('sort by date result >>>', sortedRatings);
41+
42+
return sortedRatings;
3943
};
4044

4145
const sortByUser = (projects) => {
@@ -56,6 +60,7 @@ const ProjectContainer = () => {
5660
if (error) return <p>Error :{error}</p>;
5761
// based on resolver(getAllProject) for this query, the data is stored in the data object with the key 'getAllProjects'
5862
const projects = data.getAllProjects;
63+
console.log("projects >>>>>>", projects);
5964
let sortedProjects = [];
6065
// console.log('Projects >>> ', projects);
6166
// generate an array of Project components based on data
@@ -69,6 +74,7 @@ const ProjectContainer = () => {
6974
published = { proj.published }
7075
userId = {proj.userId}
7176
username = {proj.username}
77+
createdAt = {proj.createdAt}
7278
id = {proj.id}
7379
/>;
7480
if (username === proj.username) userDisplay.push(component);
@@ -106,6 +112,7 @@ const ProjectContainer = () => {
106112
published = { proj.published }
107113
userId = {proj.userId}
108114
username = {proj.username}
115+
createdAt = {proj.createdAt}
109116
id = {proj.id}
110117
/>);
111118
});

app/src/Dashboard/gqlStrings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const GET_PROJECTS = gql`query GetAllProjects($userId: ID) {
1010
userId
1111
username
1212
published
13+
createdAt
1314
}
1415
}`;
1516

server/graphQL/resolvers/mutation.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const Project = {
2020
userId: resp.userId,
2121
likes: resp.likes,
2222
published: resp.published,
23+
createdAt: resp.createdAt,
2324
});
2425
}
2526

@@ -83,6 +84,7 @@ const Project = {
8384
userId: resp.userId,
8485
likes: resp.likes,
8586
published: resp.published,
87+
createdAt: resp.createdAt,
8688
});
8789
}
8890

@@ -104,6 +106,7 @@ const Project = {
104106
userId: resp.userId,
105107
likes: resp.likes,
106108
published: resp.published,
109+
createdAt: resp.createdAt,
107110
});
108111
}
109112

server/graphQL/resolvers/query.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const Project = {
1616
username: resp.username,
1717
likes: resp.likes,
1818
published: resp.published,
19+
createdAt: resp.createdAt,
1920
});
2021
}
2122

@@ -46,6 +47,7 @@ const Project = {
4647
username: proj.username,
4748
likes: proj.likes,
4849
published: proj.published,
50+
createdAt: proj.createdAt,
4951
}));
5052
}
5153

server/graphQL/schema/typeDefs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const Project = gql`
2222
id: ID!
2323
userId: ID!
2424
username: String!
25+
createdAt: String
2526
}
2627
2728
type Query {
File renamed without changes.

0 commit comments

Comments
 (0)