Commit 0a1f3913 authored by Anton's avatar Anton

Replace model property uuid with _uuid

parent 9c767480
......@@ -17,7 +17,7 @@ module.exports.setupArchives = (api, mapService, annotationService) => {
let data = {}
let request = {
params: {
id: req.body.id
uuid: req.body.uuid
},
user: req.user
}
......@@ -26,7 +26,7 @@ module.exports.setupArchives = (api, mapService, annotationService) => {
data.map = result.data
request = {
query: {
query: JSON.stringify({'target.id': `${config.api.uriBase}/maps/${data.map.uuid}`})
query: JSON.stringify({'target.id': data.map.id})
},
user: req.user
}
......@@ -46,7 +46,7 @@ module.exports.setupArchives = (api, mapService, annotationService) => {
if (results.maps && !copy) {
for (let map of results.maps) {
const getRequest = {
params: { id: map.uuid },
params: { uuid: map._uuid },
user: req.user
}
const item = await mapService.getHandler(getRequest)
......@@ -56,7 +56,7 @@ module.exports.setupArchives = (api, mapService, annotationService) => {
if (results.annotations && !copy) {
for (let annotation of results.annotations) {
const getRequest = {
params: { id: annotation.uuid },
params: { uuid: annotation._uuid },
user: req.user
}
const item = await annotationService.getHandler(getRequest)
......@@ -68,13 +68,14 @@ module.exports.setupArchives = (api, mapService, annotationService) => {
const mappings = {}
if (results.maps) {
for (let map of results.maps) {
let oldId = map.uuid
let oldId = map._uuid
for (let k of Object.keys(map)) {
if (k[0] === '_') map[k] = undefined
}
if (copy) {
map.title = req.body.title
map.uuid = undefined
map.id = undefined
map._uuid = undefined
}
if (!map.author) {
map.author = {
......@@ -87,7 +88,7 @@ module.exports.setupArchives = (api, mapService, annotationService) => {
user: req.user
}
const result = await mapService.postHandler(postRequest)
if (copy) mappings[oldId] = result.data.uuid
if (copy) mappings[oldId] = result.data._uuid
}
}
if (results.annotations) {
......@@ -97,7 +98,8 @@ module.exports.setupArchives = (api, mapService, annotationService) => {
}
if (copy) {
annotation.target.id = mappings[annotation.target.id]
annotation.uuid = undefined
annotation._uuid = undefined
annotation.id = undefined
}
if (!annotation.author) {
annotation.author = {
......@@ -122,7 +124,7 @@ module.exports.createArchive = async (api, data) => {
Assert.isType(data.map, 'object', 'data.map must be object')
Assert.ok(Array.isArray(data.annotations), 'data.annotations must be array')
const dir = path.join(os.tmpdir(), `archive_${ObjectUtil.slug(data.map.title)}_${data.map.uuid}`)
const dir = path.join(os.tmpdir(), `archive_${ObjectUtil.slug(data.map.title)}_${data.map._uuid}`)
await new Promise((resolve, reject) => {
rimraf(dir, err => {
......@@ -140,12 +142,12 @@ module.exports.createArchive = async (api, data) => {
await fs.mkdir(path.join(dir, 'maps'))
await fs.mkdir(path.join(dir, 'annotations'))
const mapfile = path.join('maps', `${data.map.uuid}.json`)
const mapfile = path.join('maps', `${data.map._uuid}.json`)
await fs.writeFile(path.join(dir, mapfile), JSON.stringify(data.map))
archive.addFile(path.join(dir, mapfile), mapfile)
for (let a of data.annotations) {
const annofile = path.join('annotations', `${a.uuid}.json`)
const annofile = path.join('annotations', `${a._uuid}.json`)
await fs.writeFile(path.join(dir, annofile), JSON.stringify(a))
archive.addFile(path.join(dir, annofile), annofile)
}
......
......@@ -125,7 +125,7 @@ class Profiles extends TinyEmitter {
}
_response (req, res, data = {}) {
this.emit('message', { method: req.method, id: data.uuid })
this.emit('message', { method: req.method, id: data.id })
if (typeof res === 'function') res({ data })
else if (typeof res === 'undefined') return Promise.resolve({ data })
else send(res, 200, data)
......
......@@ -29,7 +29,7 @@ const resurrectAnnotation = function (annotation) {
const fetchMetaData = async (videos, req, api) => {
for (let v of videos) {
try {
const meta = await axios.get(`${config.api.transcoderHost}/metadata/${v.annotation.uuid}`, {
const meta = await axios.get(`${config.api.transcoderHost}/metadata/${v.annotation._uuid}`, {
headers: {
Authorization: req.headers.authorization
}
......@@ -107,7 +107,7 @@ class Sessions extends TinyEmitter {
results = await _this._annotations.findHandler({
query: {
query: JSON.stringify({
'target.id': `${config.api.uriBase}/piecemaker/timelines/${map.uuid}`
'target.id': `${config.api.uriBase}/piecemaker/timelines/${map._uuid}`
})
},
user: req.user,
......@@ -120,7 +120,7 @@ class Sessions extends TinyEmitter {
}
_response (req, res, data = {}) {
this.emit('message', { method: req.method, id: data.uuid })
this.emit('message', { method: req.method, id: data.id })
if (typeof res === 'function') res({ data })
else if (typeof res === 'undefined') return Promise.resolve({ data })
else send(res, 200, data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment