Add ability to fork translationEntryVersions
This commit is contained in:
61
server/router/fork/index.js
Normal file
61
server/router/fork/index.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const express = require('express');
|
||||
|
||||
module.exports = function (options) {
|
||||
const db = options.db;
|
||||
var router = express.Router();
|
||||
|
||||
router.route('/t/:id')
|
||||
.post(function(request, response, next) {
|
||||
db.TranslationEntryVersion.findByPk(request.params.id, {
|
||||
}).then(async (translationEntryVersion) => {
|
||||
if (translationEntryVersion) {
|
||||
// fork...
|
||||
const forkedTranslationEntryVersion = await db.TranslationEntryVersion.create({
|
||||
name: translationEntryVersion.name,
|
||||
entryVersionId: translationEntryVersion.entryVersionId,
|
||||
userId: request.user.id,
|
||||
dialectId: translationEntryVersion.dialectId,
|
||||
forkedFromId: translationEntryVersion.id
|
||||
})
|
||||
if (forkedTranslationEntryVersion) {
|
||||
return response.redirect(`/v/${forkedTranslationEntryVersion.entryVersionId}/translations/${forkedTranslationEntryVersion.id}`)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/e/:id')
|
||||
.get(function(request, response, next) {
|
||||
db.TranslationEntryVersion.findByPk(request.params.id, {
|
||||
}).then(translationEntryVersion => {
|
||||
if (translationEntryVersion) {
|
||||
// choose a dialect
|
||||
next()
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
.post(function(request, response, next) {
|
||||
db.TranslationEntryVersion.findByPk(request.params.id, {
|
||||
}).then(translationEntryVersion => {
|
||||
if (translationEntryVersion) {
|
||||
// fork...
|
||||
next()
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
return router;
|
||||
};
|
||||
Reference in New Issue
Block a user