Skip to content

Commit

Permalink
added category_slug to project objects
Browse files Browse the repository at this point in the history
  • Loading branch information
da1nerd committed Dec 22, 2016
1 parent 55c950f commit 408bf41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
9 changes: 6 additions & 3 deletions __tests__/library-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ describe('Library', () => {
it('should add a project to the database', () => {
testInsert('addProject', 'getProject', project,
[source_language_en.id], [source_language_en.slug],
['id', 'category_id', 'categories']);
['id', 'category_id', 'category_slug', 'categories']);
});

it('should update a project in the database', () => {
testUpdate('addProject', 'getProject', project, projectAlt,
[source_language_en.id], [source_language_en.slug],
['id', 'category_id', 'categories']);
['id', 'category_id', 'category_slug', 'categories']);
});

it('should not add incomplete project to the database', () => {
Expand Down Expand Up @@ -455,7 +455,10 @@ describe('Library', () => {
expect(allModeResult.length).toEqual(3); // 2 projects and 1 category
var numAllProj = 0;
allModeResult.forEach(function(item) {
if(item.type == 'project') numAllProj ++;
if(item.type == 'project') {
numAllProj ++;
expect(item.category_slug).not.toBeNull();
}
});
expect(numAllProj).toEqual(2);

Expand Down
20 changes: 13 additions & 7 deletions lib/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ function Library(sqliteHelper, opts) {
* Returns meta data about a project without any localized information such as the title an description.
*/
this.getProjectMeta = function(projectSlug) {
let result = query('select * from project where slug=? limit 1', [projectSlug]);
let result = query('select p.*, c.slug as category_slug from project as p' +
' left join category as c on c.id=p.category_id' +
' where p.slug=? limit 1', [projectSlug]);
if(result.length > 0) {
delete result[0].id;
delete result[0].name;
Expand Down Expand Up @@ -627,8 +629,9 @@ function Library(sqliteHelper, opts) {
projectSlug = languageSlug.projectSlug;
languageSlug = languageSlug.languageSlug;
}
let result = query('select * from project' +
' where slug=? and source_language_id in (' +
let result = query('select p.*, c.slug as category_slug from project as p' +
' left join category as c on c.id=p.category_id' +
' where p.slug=? and p.source_language_id in (' +
' select id from source_language where slug=?)' +
' limit 1', [projectSlug, languageSlug]);
if(result.length > 0) {
Expand All @@ -648,9 +651,10 @@ function Library(sqliteHelper, opts) {
getProjects: function(languageSlug) {
let result;
if(languageSlug) {
result = query('select * from project' +
' where source_language_id in (select id from source_language where slug=?)' +
' order by sort asc', [languageSlug]);
result = query('select p.*, c.slug as category_slug from project as p' +
' left join category as c on c.id=p.category_id' +
' where p.source_language_id in (select id from source_language where slug=?)' +
' order by p.sort asc', [languageSlug]);
} else {
result = query('select * from project' +
' group by slug order by sort asc');
Expand Down Expand Up @@ -1058,11 +1062,13 @@ function Library(sqliteHelper, opts) {
let results = query("select l.slug as language_slug, l.name as language_name, l.direction," +
" p.slug as project_slug, p.category_id, p.name as project_name, p.desc, p.icon, p.sort, p.chunks_url," +
" r.id as resource_id, r.slug as resource_slug, r.name as resource_name, r.type, r.translate_mode, r.checking_level, r.comments, r.pub_date, r.license, r.version," +
" lri.translation_words_assignments_url" +
" lri.translation_words_assignments_url," +
" c.slug as category_slug " +
" from source_language as l" +
" left join project as p on p.source_language_id=l.id" +
" left join resource as r on r.project_id=p.id" +
" left join legacy_resource_info as lri on lri.resource_id=r.id" +
" left join category as c on c.id=p.category_id" +
" where l.slug like(?) and p.slug like(?) and r.slug like(?)" +
" and r.checking_level >= ?" +
condition_max_checking +
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "door43-client",
"version": "0.9.1",
"version": "0.9.2",
"description": "A client library for interacting with the Door43 Resource API.",
"main": "./lib/main.js",
"scripts": {
Expand Down

0 comments on commit 408bf41

Please sign in to comment.