Refactor app management to use Drizzle ORM
- Replaced Sequelize models with Drizzle ORM for app and app list management. - Updated routes in app-manager to utilize new database queries. - Removed obsolete Sequelize model files for app, app list, and app domain. - Introduced new helper functions for app and app domain management. - Enhanced user app management with improved file handling and user migration. - Adjusted public API routes to align with new database structure. - Implemented caching mechanisms for domain management.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { app } from '@/app.ts';
|
||||
import { app, db, schema } from '@/app.ts';
|
||||
import { Org } from '@/models/org.ts';
|
||||
import { User } from '@/models/user.ts';
|
||||
import { Op } from 'sequelize';
|
||||
import { sql, eq } from 'drizzle-orm';
|
||||
|
||||
app
|
||||
.route({
|
||||
@@ -11,19 +11,11 @@ app
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const list = await Org.findAll({
|
||||
order: [['updatedAt', 'DESC']],
|
||||
where: {
|
||||
users: {
|
||||
[Op.contains]: [
|
||||
{
|
||||
uid: tokenUser.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
logging: false,
|
||||
});
|
||||
const list = await db
|
||||
.select()
|
||||
.from(schema.cfOrgs)
|
||||
.where(sql`${schema.cfOrgs.users} @> ${JSON.stringify([{ uid: tokenUser.id }])}::jsonb`)
|
||||
.orderBy(sql`${schema.cfOrgs.updatedAt} DESC`);
|
||||
|
||||
ctx.body = list;
|
||||
return ctx;
|
||||
@@ -49,14 +41,16 @@ app
|
||||
ctx.throw('org not found');
|
||||
}
|
||||
org.description = description;
|
||||
await org.save();
|
||||
const user = await User.findOne({ where: { username } });
|
||||
user.description = description;
|
||||
await user.save();
|
||||
await db.update(schema.cfOrgs).set({ description }).where(eq(schema.cfOrgs.id, org.id));
|
||||
const user = await User.findOne({ username });
|
||||
if (user) {
|
||||
user.description = description;
|
||||
await user.save();
|
||||
}
|
||||
ctx.body = {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
description: user.description,
|
||||
id: user?.id,
|
||||
username: user?.username,
|
||||
description: user?.description,
|
||||
};
|
||||
return;
|
||||
}
|
||||
@@ -100,11 +94,11 @@ app
|
||||
if (owner.uid !== tokenUser.id) {
|
||||
ctx.throw('Permission denied');
|
||||
}
|
||||
await org.destroy({ force: true });
|
||||
const orgUser = await User.findOne({
|
||||
where: { username },
|
||||
});
|
||||
await orgUser.destroy({ force: true });
|
||||
await db.delete(schema.cfOrgs).where(eq(schema.cfOrgs.id, org.id));
|
||||
const orgUser = await User.findOne({ username });
|
||||
if (orgUser) {
|
||||
await db.delete(schema.cfUser).where(eq(schema.cfUser.id, orgUser.id));
|
||||
}
|
||||
ctx.body = 'success';
|
||||
})
|
||||
.addTo(app);
|
||||
@@ -160,12 +154,7 @@ app
|
||||
};
|
||||
return;
|
||||
}
|
||||
const usernameUser = await User.findOne({
|
||||
where: { username },
|
||||
attributes: {
|
||||
exclude: ['password', 'salt'],
|
||||
},
|
||||
});
|
||||
const usernameUser = await User.findOne({ username });
|
||||
|
||||
if (!usernameUser) {
|
||||
ctx.body = {
|
||||
|
||||
Reference in New Issue
Block a user