Updated the v2 api to deal with type column

refs #10922

This replaces references to the `page` column with references to the
`type` column.
This commit is contained in:
Fabien O'Carroll 2019-07-23 15:28:53 +08:00
parent dc3345b1c5
commit 57afb2de2b
5 changed files with 34 additions and 32 deletions

View File

@ -55,9 +55,9 @@ function defaultFormat(frame) {
*/
const forcePageFilter = (frame) => {
if (frame.options.filter) {
frame.options.filter = `(${frame.options.filter})+page:true`;
frame.options.filter = `(${frame.options.filter})+type:page`;
} else {
frame.options.filter = 'page:true';
frame.options.filter = 'type:page';
}
};
@ -123,7 +123,7 @@ module.exports = {
// @NOTE: force storing page
if (options.add) {
frame.data.pages[0].page = true;
frame.data.pages[0].type = 'page';
}
// CASE: Transform short to long format
@ -163,7 +163,7 @@ module.exports = {
destroy(apiConfig, frame) {
frame.options.destroyBy = {
id: frame.options.id,
page: true
type: 'page'
};
defaultFormat(frame);

View File

@ -64,9 +64,9 @@ function defaultFormat(frame) {
*/
const forcePageFilter = (frame) => {
if (frame.options.filter) {
frame.options.filter = `(${frame.options.filter})+page:false`;
frame.options.filter = `(${frame.options.filter})+type:post`;
} else {
frame.options.filter = 'page:false';
frame.options.filter = 'type:post';
}
};
@ -158,7 +158,7 @@ module.exports = {
// @NOTE: force adding post
if (options.add) {
frame.data.posts[0].page = false;
frame.data.posts[0].type = 'post';
}
// CASE: Transform short to long format
@ -196,7 +196,7 @@ module.exports = {
destroy(apiConfig, frame) {
frame.options.destroyBy = {
id: frame.options.id,
page: false
type: 'post'
};
defaultFormat(frame);

View File

@ -57,6 +57,8 @@ const mapPost = (model, frame) => {
});
}
delete jsonModel.type;
return jsonModel;
};

View File

@ -13,7 +13,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('page:true');
frame.options.filter.should.eql('type:page');
});
it('combine filters', function () {
@ -27,7 +27,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(status:published+tag:eins)+page:true');
frame.options.filter.should.eql('(status:published+tag:eins)+type:page');
});
it('combine filters', function () {
@ -41,7 +41,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false+tag:eins)+page:true');
frame.options.filter.should.eql('(page:false+tag:eins)+type:page');
});
it('combine filters', function () {
@ -55,7 +55,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+page:true');
frame.options.filter.should.eql('(page:false)+type:page');
});
it('remove mobiledoc option from formats', function () {
@ -87,7 +87,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('page:true');
frame.options.filter.should.eql('type:page');
});
it('content api default', function () {
@ -107,7 +107,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('page:true');
frame.options.filter.should.eql('type:page');
});
it('admin api default', function () {
@ -127,7 +127,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(page:true)+status:[draft,published,scheduled]');
frame.options.filter.should.eql('(type:page)+status:[draft,published,scheduled]');
});
it('custom page filter', function () {
@ -142,7 +142,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+page:true');
frame.options.filter.should.eql('(page:false)+type:page');
});
it('custom status filter', function () {
@ -163,7 +163,7 @@ describe('Unit: v2/utils/serializers/input/pages', function () {
};
serializers.input.pages.read(apiConfig, frame);
frame.options.filter.should.eql('(status:draft)+page:true');
frame.options.filter.should.eql('(status:draft)+type:page');
});
it('remove mobiledoc option from formats', function () {

View File

@ -21,7 +21,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('page:false');
frame.options.filter.should.eql('type:post');
});
it('should not work for non public context', function () {
@ -36,7 +36,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.browse(apiConfig, frame);
should.equal(frame.options.filter, '(page:false)+status:[draft,published,scheduled]');
should.equal(frame.options.filter, '(type:post)+status:[draft,published,scheduled]');
});
it('combine filters', function () {
@ -56,7 +56,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(status:published+tag:eins)+page:false');
frame.options.filter.should.eql('(status:published+tag:eins)+type:post');
});
it('combine filters', function () {
@ -76,7 +76,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:true+tag:eins)+page:false');
frame.options.filter.should.eql('(page:true+tag:eins)+type:post');
});
it('combine filters', function () {
@ -96,7 +96,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('(page:true)+page:false');
frame.options.filter.should.eql('(page:true)+type:post');
});
it('combine filters', function () {
@ -116,7 +116,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.browse(apiConfig, frame);
frame.options.filter.should.eql('((page:true,page:false))+page:false');
frame.options.filter.should.eql('((page:true,page:false))+type:post');
});
it('remove mobiledoc option from formats', function () {
@ -137,7 +137,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
});
describe('read', function () {
it('with apiType of "content" it forces page filter', function () {
it('with apiType of "content" it forces type filter', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
@ -146,24 +146,24 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('page:false');
frame.options.filter.should.eql('type:post');
});
it('with apiType of "content" it forces page false filter', function () {
it('with apiType of "content" it forces type:post filter', function () {
const apiConfig = {};
const frame = {
apiType: 'content',
options: {
filter: 'page:true'
filter: 'type:page'
},
data: {}
};
serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(page:true)+page:false');
frame.options.filter.should.eql('(type:page)+type:post');
});
it('with apiType of "admin" it forces page & status false filter', function () {
it('with apiType of "admin" it forces type & status false filter', function () {
const apiConfig = {};
const frame = {
apiType: 'admin',
@ -179,10 +179,10 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(page:false)+status:[draft,published,scheduled]');
frame.options.filter.should.eql('(type:post)+status:[draft,published,scheduled]');
});
it('with apiType of "admin" it forces page filter & respects custom status filter', function () {
it('with apiType of "admin" it forces type:post filter & respects custom status filter', function () {
const apiConfig = {};
const frame = {
apiType: 'admin',
@ -199,7 +199,7 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
};
serializers.input.posts.read(apiConfig, frame);
frame.options.filter.should.eql('(status:draft)+page:false');
frame.options.filter.should.eql('(status:draft)+type:post');
});
it('remove mobiledoc option from formats', function () {