Skip to content

Commit 30bb81c

Browse files
JulienKerleroRenzoPratsAntoineRelief
authored
feat: can now edit page / step 's icons (#749)
* Modified models and mutations to add icon field to page and step * Modified the type files to add icon * Allows icon modification * Removed logging * refactor: improve check of args in edit page & edit step mutations --------- Co-authored-by: RenzoPrats <renzoprats@icloud.com> Co-authored-by: Antoine Hurard <antoine.reliefapps@gmail.com>
1 parent e37b342 commit 30bb81c

File tree

7 files changed

+36
-33
lines changed

7 files changed

+36
-33
lines changed

src/i18n/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
}
191191
},
192192
"errors": {
193-
"invalidArguments": "Either name, permissions, or visibility must be provided."
193+
"invalidArguments": "Either name, permissions, visibility or icon must be provided to update the page."
194194
}
195195
}
196196
},
@@ -244,7 +244,7 @@
244244
},
245245
"edit": {
246246
"errors": {
247-
"invalidArguments": "Either name, type, content or permissions must be provided."
247+
"invalidArguments": "Either name, type, content, icon or permissions must be provided."
248248
}
249249
}
250250
},

src/models/page.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type PageContextT = (
2828
export interface Page extends Document {
2929
kind: 'Page';
3030
name: string;
31+
icon: string;
3132
createdAt: Date;
3233
modifiedAt: Date;
3334
type: string;
@@ -58,6 +59,7 @@ export interface Page extends Document {
5859
const pageSchema = new Schema<Page>(
5960
{
6061
name: String,
62+
icon: String,
6163
type: {
6264
type: String,
6365
enum: Object.values(contentType),

src/models/step.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Workflow } from './workflow.model';
99
export interface Step extends Document {
1010
kind: 'Step';
1111
name: string;
12+
icon: string;
1213
createdAt: Date;
1314
modifiedAt: Date;
1415
type: string;
@@ -29,6 +30,7 @@ export interface Step extends Document {
2930
const stepSchema = new Schema<Step>(
3031
{
3132
name: String,
33+
icon: String,
3234
type: {
3335
type: String,
3436
enum: Object.values(contentType),

src/schema/mutation/editPage.mutation.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import GraphQLJSON from 'graphql-type-json';
99
import { contentType } from '@const/enumTypes';
1010
import { PageType } from '../types';
1111
import { Page, Workflow, Dashboard, Form } from '@models';
12-
import { isArray, isNil } from 'lodash';
12+
import { cloneDeep, isArray, isEmpty, isNil, omit } from 'lodash';
1313
import extendAbilityForPage from '@security/extendAbilityForPage';
1414
import { logger } from '@services/logger.service';
1515

@@ -38,6 +38,7 @@ export default {
3838
args: {
3939
id: { type: new GraphQLNonNull(GraphQLID) },
4040
name: { type: GraphQLString },
41+
icon: { type: GraphQLString },
4142
permissions: { type: GraphQLJSON },
4243
visible: { type: GraphQLBoolean },
4344
},
@@ -50,11 +51,17 @@ export default {
5051
context.i18next.t('common.errors.userNotLogged')
5152
);
5253
}
53-
// check inputs
54-
if (!args || (!args.name && !args.permissions && isNil(args.visible)))
54+
/**
55+
* Check if at least one of the required arguments is provided.
56+
* Else, send error.
57+
* This way, we check for the existence of keys, except id in args
58+
*/
59+
if (isEmpty(cloneDeep(omit(args, ['id'])))) {
5560
throw new GraphQLError(
5661
context.i18next.t('mutations.page.edit.errors.invalidArguments')
5762
);
63+
}
64+
5865
// get data
5966
let page = await Page.findById(args.id);
6067
if (!page) {
@@ -68,19 +75,11 @@ export default {
6875
);
6976
}
7077

71-
// update name
72-
/* const update: {
73-
modifiedAt?: Date;
74-
name?: string;
75-
} = {
76-
modifiedAt: new Date(),
77-
}; */
78-
79-
const update: {
80-
name?: string;
81-
} = {};
82-
83-
Object.assign(update, args.name && { name: args.name });
78+
// Create update
79+
const update = {
80+
...(args.name && { name: args.name }),
81+
...(args.icon && { icon: args.icon }),
82+
};
8483

8584
// Updating permissions
8685
const permissionsUpdate: any = {};

src/schema/mutation/editStep.mutation.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
GraphQLError,
66
} from 'graphql';
77
import GraphQLJSON from 'graphql-type-json';
8-
import { isArray } from 'lodash';
8+
import { cloneDeep, isArray, isEmpty, omit } from 'lodash';
99
import { contentType } from '@const/enumTypes';
1010
import { StepType } from '../types';
1111
import { Dashboard, Form, Step } from '@models';
@@ -36,6 +36,7 @@ export default {
3636
args: {
3737
id: { type: new GraphQLNonNull(GraphQLID) },
3838
name: { type: GraphQLString },
39+
icon: { type: GraphQLString },
3940
type: { type: GraphQLString },
4041
content: { type: GraphQLID },
4142
permissions: { type: GraphQLJSON },
@@ -49,11 +50,12 @@ export default {
4950
context.i18next.t('common.errors.userNotLogged')
5051
);
5152
}
52-
// check inputs
53-
if (
54-
!args ||
55-
(!args.name && !args.type && !args.content && !args.permissions)
56-
) {
53+
/**
54+
* Check if at least one of the required arguments is provided.
55+
* Else, send error.
56+
* This way, we check for the existence of keys, except id in args
57+
*/
58+
if (isEmpty(cloneDeep(omit(args, ['id'])))) {
5759
throw new GraphQLError(
5860
context.i18next.t('mutations.step.edit.errors.invalidArguments')
5961
);
@@ -85,17 +87,13 @@ export default {
8587
);
8688
}
8789

88-
// defining what to update
90+
// Create update
8991
const update = {
90-
//modifiedAt: new Date(),
92+
...(args.name && { name: args.name }),
93+
...(args.icon && { icon: args.icon }),
94+
...(args.type && { type: args.type }),
95+
...(args.content && { content: args.content }),
9196
};
92-
Object.assign(
93-
update,
94-
args.name && { name: args.name },
95-
args.type && { type: args.type },
96-
args.content && { content: args.content }
97-
);
98-
9997
// Updating permissions
10098
const permissionsUpdate: any = {};
10199
if (args.permissions) {

src/schema/types/page.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const PageType = new GraphQLObjectType({
2626
},
2727
},
2828
name: { type: GraphQLString },
29+
icon: { type: GraphQLString },
2930
visible: {
3031
type: GraphQLBoolean,
3132
resolve(parent) {

src/schema/types/step.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const StepType = new GraphQLObjectType({
2222
},
2323
},
2424
name: { type: GraphQLString },
25+
icon: { type: GraphQLString },
2526
createdAt: { type: GraphQLString },
2627
modifiedAt: { type: GraphQLString },
2728
type: { type: ContentEnumType },

0 commit comments

Comments
 (0)