Completed
Push — master ( 430c18...52d1c6 )
by
unknown
54s
created

metas.js ➔ add   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
c 0
b 0
f 0
nc 4
dl 0
loc 22
rs 8.6737
nop 3
1
import {
2
  cmsData
3
  ,config
4
} from '../../'
5
6
export function add(json, type, date = null) {
7
  let meta = config.meta.name
8
  var currentDate = (date != null && date !== '') ? date : new Date()
9
  var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + cmsData.revision.removeStatusAndDateFromFileName(currentDate.toISOString())) + ''
10
11
  if(json[meta].date == null) {
12
    json[meta].date = currentDate
13
  }
14
  json[meta].latest = {
15
    date: currentDate,
16
    abeUrl: abeUrl
17
  }
18
  json[meta].status = type
19
  if(json[meta][type] == null) {
20
    json[meta][type] = {latest: {}}
21
    json[meta][type].date = currentDate
22
    json[meta][type].abeUrl = abeUrl
23
  }
24
  // json[meta][type].latest = JSON.parse(JSON.stringify(obj))
25
  json[meta][type].latest.date = currentDate
26
  json[meta][type].latest.abeUrl = abeUrl
27
}
28
29
30
export function create(json, template, url) {
31
  let meta = config.meta.name
32
  if (json[meta] == null) {
33
    json[meta] = {}
34
  }
35
36
  json[meta].template = template
37
  json[meta].link = url
38
39
  return json
40
}
41