From 93a3397c586b910a45871cd76f1392e880e53041 Mon Sep 17 00:00:00 2001 From: Chris Davis Date: Wed, 29 May 2019 13:25:02 -0500 Subject: [PATCH 1/2] Sorting works! --- .../api/src/resources/environment/resolvers.js | 6 +++++- services/api/src/resources/project/resolvers.js | 4 +++- services/api/src/typeDefs.js | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/services/api/src/resources/environment/resolvers.js b/services/api/src/resources/environment/resolvers.js index 9e0d79b671..4ddd322731 100644 --- a/services/api/src/resources/environment/resolvers.js +++ b/services/api/src/resources/environment/resolvers.js @@ -658,8 +658,12 @@ 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)); + + console.warn(rows) return rows; }; diff --git a/services/api/src/resources/project/resolvers.js b/services/api/src/resources/project/resolvers.js index 17a6c843ec..8f5835df32 100644 --- a/services/api/src/resources/project/resolvers.js +++ b/services/api/src/resources/project/resolvers.js @@ -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; diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 580b28d974..a48150d0f7 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -66,6 +66,16 @@ const typeDefs = gql` FAILED } + enum EnvOrderType { + NAME + UPDATED + } + + enum ProjectOrderType { + NAME + CREATED + } + type File { id: Int filename: String @@ -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) """ @@ -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 From f510284c2af9e5cce0eeda3cb68cc153660c7a0e Mon Sep 17 00:00:00 2001 From: Chris Davis Date: Wed, 29 May 2019 15:05:20 -0500 Subject: [PATCH 2/2] Removing errant console logging statement. --- services/api/src/resources/environment/resolvers.js | 1 - 1 file changed, 1 deletion(-) diff --git a/services/api/src/resources/environment/resolvers.js b/services/api/src/resources/environment/resolvers.js index 4ddd322731..607d62fbf5 100644 --- a/services/api/src/resources/environment/resolvers.js +++ b/services/api/src/resources/environment/resolvers.js @@ -663,7 +663,6 @@ const getAllEnvironments = async ( const prep = prepare(sqlClient, `SELECT * FROM environment ${where}${order}`); const rows = await query(sqlClient, prep(args)); - console.warn(rows) return rows; };