feat: add snippet and test for supa db
This commit is contained in:
@@ -140,44 +140,49 @@ app
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { appKey, files, version } = ctx.query.data;
|
||||
if (!appKey) {
|
||||
throw new CustomError('appKey is required');
|
||||
}
|
||||
if (!files || !files.length) {
|
||||
throw new CustomError('files is required');
|
||||
}
|
||||
let am = await AppModel.findOne({ where: { key: appKey, uid: tokenUser.id } });
|
||||
if (!am) {
|
||||
am = await AppModel.create({
|
||||
user: tokenUser.username,
|
||||
key: appKey,
|
||||
uid: tokenUser.id,
|
||||
version: '0.0.0',
|
||||
title: appKey,
|
||||
data: {
|
||||
files: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
let app = await AppListModel.findOne({ where: { version: version, key: appKey, uid: tokenUser.id } });
|
||||
if (!app) {
|
||||
// throw new CustomError('app not found');
|
||||
app = await AppListModel.create({
|
||||
key: appKey,
|
||||
version,
|
||||
uid: tokenUser.id,
|
||||
data: {
|
||||
files: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
const dataFiles = app.data.files || [];
|
||||
const newFiles = _.uniqBy([...dataFiles, ...files], 'name');
|
||||
const res = await app.update({ data: { ...app.data, files: newFiles } });
|
||||
try {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { appKey, files, version } = ctx.query.data;
|
||||
if (!appKey) {
|
||||
throw new CustomError('appKey is required');
|
||||
}
|
||||
if (!files || !files.length) {
|
||||
throw new CustomError('files is required');
|
||||
}
|
||||
let am = await AppModel.findOne({ where: { key: appKey, uid: tokenUser.id } });
|
||||
if (!am) {
|
||||
am = await AppModel.create({
|
||||
user: tokenUser.username,
|
||||
key: appKey,
|
||||
uid: tokenUser.id,
|
||||
version: '0.0.0',
|
||||
title: appKey,
|
||||
data: {
|
||||
files: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
let app = await AppListModel.findOne({ where: { version: version, key: appKey, uid: tokenUser.id } });
|
||||
if (!app) {
|
||||
// throw new CustomError('app not found');
|
||||
app = await AppListModel.create({
|
||||
key: appKey,
|
||||
version,
|
||||
uid: tokenUser.id,
|
||||
data: {
|
||||
files: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
const dataFiles = app.data.files || [];
|
||||
const newFiles = _.uniqBy([...dataFiles, ...files], 'name');
|
||||
const res = await app.update({ data: { ...app.data, files: newFiles } });
|
||||
|
||||
ctx.body = prefixFix(res, tokenUser.username);
|
||||
ctx.body = prefixFix(res, tokenUser.username);
|
||||
} catch (e) {
|
||||
console.log('update error', e);
|
||||
throw new CustomError(e.message);
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user