Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create squiggle mutation #172

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions planning/v1/ROLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@

---

## Squiggle Section

### Squiggle Permissions

| Permission Name | Description |
| ------------------ | ------------------------- |
| squiggle.write.new | Can create a new squiggle |
| | |

### Squiggle Roles

| Role Name | squiggle.write.new |
| -------------- | ------------------ |
| squiggle.admin | Y |
| | |

---

## Tag Section

### Tag Permissions
Expand All @@ -99,21 +117,22 @@

---

### Live Section
### Live Section

### Live Permissions

| Permission Name | Description |
| --------------- | ---------------------------|
| live.read.all | Can read all live data |
| live.write.all | Can add/edit all live data |
| Permission Name | Description |
| --------------- | -------------------------- |
| live.read.all | Can read all live data |
| live.write.all | Can add/edit all live data |

### Live Roles

| Role Name | live.read.all | live.write.all |
| ------------------|------------------|-----------------|
| live.verified | Y | N |
| live.superadmin | Y | Y |
| Role Name | live.read.all | live.write.all |
| --------------- | ------------- | -------------- |
| live.verified | Y | N |
| live.superadmin | Y | Y |

### Media Section

### Media Permissions
Expand All @@ -126,7 +145,7 @@

### Media Roles

| Role Name | media.write.new | media.write.self | media.write.all |
| ----------- | --------------- | ---------------- | ---------------- |
| media.team | Y | Y | N |
| media.admin | Y | Y | Y |
| Role Name | media.write.new | media.write.self | media.write.all |
| ----------- | --------------- | ---------------- | --------------- |
| media.team | Y | Y | N |
| media.admin | Y | Y | Y |
14 changes: 14 additions & 0 deletions server/schema/squiggle/squiggle.datasources.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,24 @@ const find = async (query, limit, offset) => {
}
};

const create = async (squiggleType, content) => {
try {
const _squiggle = await SquiggleModel.create({
squiggleType,
content,
});

return _squiggle;
} catch (error) {
throw APIError(null, error);
}
};
rutajdash marked this conversation as resolved.
Show resolved Hide resolved

const SquiggleDataSources = () => ({
getLatest,
findByID,
find,
create,
});

module.exports = SquiggleDataSources;
17 changes: 17 additions & 0 deletions server/schema/squiggle/squiggle.mutation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { GraphQLObjectType, GraphQLNonNull, GraphQLString } = require('../scalars');
const { createSquiggle } = require('./squiggle.resolver');

const SquiggleType = require('./squiggle.type');

module.exports = new GraphQLObjectType({
name: 'SquiggleMutation',
fields: {
createSquiggle: {
type: SquiggleType,
args: {
content: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: createSquiggle,
},
},
});
19 changes: 19 additions & 0 deletions server/schema/squiggle/squiggle.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,30 @@
* @since 0.1.0
*/

const UserPermission = require('../../utils/userAuth/permission');
const { APIError } = require('../../utils/exception');

const DEF_LIMIT = 10;
const DEF_OFFSET = 0;
module.exports = {
createSquiggle: async (
_parent,
{ squiggleType, content },
{ session, authToken, decodedToken, API: { Squiggle } }
) => {
try {
if (!UserPermission.exists(session, authToken, decodedToken, 'squiggle.write.new')) {
throw APIError('FORBIDDEN', null, {
reason: 'The user does not have the required permissions to create a squiggle.',
});
}
const _squiggle = await Squiggle.create(squiggleType, content);

rutajdash marked this conversation as resolved.
Show resolved Hide resolved
return _squiggle;
} catch (error) {
throw APIError(null, error);
}
},
getLatestSquiggle: async (_parent, _args, { API: { Squiggle } }, _) => {
try {
const _squiggle = await Squiggle.getLatest();
Expand Down
2 changes: 2 additions & 0 deletions server/schema/squiggle/squiggle.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ const {
// GraphQLJSONObject,
} = require('../scalars');

const SquiggleMutation = require('./squiggle.mutation');
const SquiggleQuery = require('./squiggle.query');
const SquiggleType = require('./squiggle.type');

module.exports = new GraphQLSchema({
types: [SquiggleType],
query: SquiggleQuery,
mutation: SquiggleMutation,
});