color editing
This commit is contained in:
@ -11,14 +11,17 @@ import { Collection } from '../models';
|
||||
const router = new Router();
|
||||
|
||||
router.post('collections.create', auth(), async ctx => {
|
||||
const { name, description, type } = ctx.body;
|
||||
const { name, color, description, type } = ctx.body;
|
||||
ctx.assertPresent(name, 'name is required');
|
||||
if (color)
|
||||
ctx.assertHexColor(color, 'Invalid hex value (please use format #FFFFFF)');
|
||||
|
||||
const user = ctx.state.user;
|
||||
|
||||
const collection = await Collection.create({
|
||||
name,
|
||||
description,
|
||||
color,
|
||||
type: type || 'atlas',
|
||||
teamId: user.teamId,
|
||||
creatorId: user.id,
|
||||
@ -30,11 +33,14 @@ router.post('collections.create', auth(), async ctx => {
|
||||
});
|
||||
|
||||
router.post('collections.update', auth(), async ctx => {
|
||||
const { id, name } = ctx.body;
|
||||
const { id, name, color } = ctx.body;
|
||||
ctx.assertPresent(name, 'name is required');
|
||||
if (color)
|
||||
ctx.assertHexColor(color, 'Invalid hex value (please use format #FFFFFF)');
|
||||
|
||||
const collection = await Collection.findById(id);
|
||||
collection.name = name;
|
||||
collection.color = color;
|
||||
await collection.save();
|
||||
|
||||
ctx.body = {
|
||||
|
@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
import apiError from '../../errors';
|
||||
import validator from 'validator';
|
||||
import { validateColorHex } from '../../../shared/utils/color';
|
||||
|
||||
export default function validation() {
|
||||
return function validationMiddleware(ctx: Object, next: Function) {
|
||||
@ -28,6 +29,12 @@ export default function validation() {
|
||||
}
|
||||
};
|
||||
|
||||
ctx.assertHexColor = (value, message) => {
|
||||
if (!validateColorHex(value)) {
|
||||
throw apiError(400, 'validation_error', message);
|
||||
}
|
||||
};
|
||||
|
||||
return next();
|
||||
};
|
||||
}
|
||||
|
11
server/migrations/20171023064220-collection-color.js
Normal file
11
server/migrations/20171023064220-collection-color.js
Normal file
@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
up: function(queryInterface, Sequelize) {
|
||||
queryInterface.addColumn('collections', 'color', {
|
||||
type: Sequelize.TEXT,
|
||||
});
|
||||
},
|
||||
|
||||
down: function(queryInterface, Sequelize) {
|
||||
queryInterface.removeColumn('collections', 'color');
|
||||
},
|
||||
};
|
@ -22,6 +22,7 @@ const Collection = sequelize.define(
|
||||
urlId: { type: DataTypes.STRING, unique: true },
|
||||
name: DataTypes.STRING,
|
||||
description: DataTypes.STRING,
|
||||
color: DataTypes.STRING,
|
||||
type: {
|
||||
type: DataTypes.STRING,
|
||||
validate: { isIn: allowedCollectionTypes },
|
||||
|
@ -5,7 +5,7 @@ import randomstring from 'randomstring';
|
||||
|
||||
import isUUID from 'validator/lib/isUUID';
|
||||
import { DataTypes, sequelize } from '../sequelize';
|
||||
import parseTitle from '../../shared/parseTitle';
|
||||
import parseTitle from '../../shared/utils/parseTitle.js';
|
||||
import Revision from './Revision';
|
||||
|
||||
const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
|
||||
|
@ -11,6 +11,7 @@ async function present(ctx: Object, collection: Collection) {
|
||||
url: collection.getUrl(),
|
||||
name: collection.name,
|
||||
description: collection.description,
|
||||
color: collection.color || '#4E5C6E',
|
||||
type: collection.type,
|
||||
createdAt: collection.createdAt,
|
||||
updatedAt: collection.updatedAt,
|
||||
|
Reference in New Issue
Block a user