Skip to content

Commit

Permalink
Merge pull request #1109 from amazeeio/issue_1038
Browse files Browse the repository at this point in the history
Add `order` field to `allProjects` and `allEnvironments` GraphQL API endpoints
  • Loading branch information
Schnitzel committed Jun 1, 2019
2 parents 28788b6 + f510284 commit 2a4b2c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion services/api/src/resources/environment/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,11 @@ const getAllEnvironments = async (
'deleted = "0000-00-00 00:00:00"',
]);

const prep = prepare(sqlClient, `SELECT * FROM environment ${where}`);
const order = args.order ? ` ORDER BY ${R.toLower(args.order)} ASC` : ''

const prep = prepare(sqlClient, `SELECT * FROM environment ${where}${order}`);
const rows = await query(sqlClient, prep(args));

return rows;
};

Expand Down
4 changes: 3 additions & 1 deletion services/api/src/resources/project/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const getAllProjects = async (
),
]);

const prep = prepare(sqlClient, `SELECT * FROM project ${where}`);
const order = args.order ? ` ORDER BY ${R.toLower(args.order)} ASC` : ''

const prep = prepare(sqlClient, `SELECT * FROM project ${where}${order}`);
const rows = await query(sqlClient, prep(args));

return rows;
Expand Down
14 changes: 12 additions & 2 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ const typeDefs = gql`
FAILED
}
enum EnvOrderType {
NAME
UPDATED
}
enum ProjectOrderType {
NAME
CREATED
}
type File {
id: Int
filename: String
Expand Down Expand Up @@ -472,7 +482,7 @@ const typeDefs = gql`
"""
Returns all Project Objects matching given filters (all if no filter defined)
"""
allProjects(createdAfter: String, gitUrl: String): [Project]
allProjects(createdAfter: String, gitUrl: String, order: ProjectOrderType): [Project]
"""
Returns all Customer Objects matching given filter (all if no filter defined)
"""
Expand All @@ -484,7 +494,7 @@ const typeDefs = gql`
"""
Returns all Environments matching given filter (all if no filter defined)
"""
allEnvironments(createdAfter: String, type: EnvType): [Environment]
allEnvironments(createdAfter: String, type: EnvType, order: EnvOrderType): [Environment]
}
# Must provide id OR name
Expand Down

0 comments on commit 2a4b2c7

Please sign in to comment.