Completed
Push — master ( 1fc2c9...675e71 )
by greg
01:46
created

src/cli/cms/data/metas.js   A

Complexity

Total Complexity 20
Complexity/F 6.67

Size

Lines of Code 52
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 20
c 1
b 0
f 0
nc 1
mnd 1
bc 8
fnc 3
dl 0
loc 52
rs 10
bpm 2.6666
cpm 6.6666
noi 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A metas.js ➔ get 0 23 1
C metas.js ➔ add 0 23 10
1
import {
2
  cmsData
3
  ,config
4
} from '../../'
5
6
export function add(tpl, json, type, obj = {}, date = null, realType = 'draft') {
7
  let meta = config.meta.name
8
9
  var currentDate = (typeof date !== 'undefined' && date !== null && date !== '') ? date : new Date()
10
  var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + cmsData.revision.removeStatusAndDateFromFileName(currentDate.toISOString())) + ''
11
12
  if(typeof json[meta].date === 'undefined' || json[meta].date === null) {
13
    json[meta].date = currentDate
14
  }
15
  json[meta].latest = {
16
    date: currentDate,
17
    abeUrl: abeUrl
18
  }
19
  json[meta].status = realType === 'reject' ? 'draft' : realType
20
  if(typeof json[meta][type] === 'undefined' || json[meta][type] === null) {
21
    json[meta][type] = JSON.parse(JSON.stringify(obj))
22
    json[meta][type].date = currentDate
23
    json[meta][type].abeUrl = abeUrl
24
  }
25
  json[meta][type].latest = JSON.parse(JSON.stringify(obj))
26
  json[meta][type].latest.date = currentDate
27
  json[meta][type].latest.abeUrl = abeUrl
28
}
29
30
export function get(arr) {
31
  var res = []
32
  Array.prototype.forEach.call(arr, (file) => {
33
    let meta = config.meta.name
34
35
    var jsonPath = cmsData.file.fromUrl(file.path).json.path
36
    var json = cmsData.file.get(jsonPath)
37
    if(typeof json[meta] === 'undefined' || json[meta] === null) json[meta] = {}
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
38
    file['template'] = json[meta].template
39
    if(typeof json[meta].latest !== 'undefined' && json[meta].latest !== null) {
40
      file['date'] = json[meta].latest.date
41
    }
42
    if(typeof json[meta].complete === 'undefined' || json[meta].complete === null) {
43
      json[meta].complete = 0
44
    }
45
    if(typeof json[meta] !== 'undefined' && json[meta] !== null) {
46
      file[config.meta.name] = json[meta]
47
    }
48
    res.push(file)
49
  })
50
51
  return res
52
}