|
@@ -1,5 +1,6 @@
|
|
|
import { Injectable } from '@angular/core';
|
|
|
import Parse from 'parse';
|
|
|
+import { CloudQuery } from 'src/lib/ncloud';
|
|
|
|
|
|
// 添加自定义教师接口
|
|
|
export interface CustomTeacher {
|
|
@@ -51,7 +52,7 @@ export class DatabaseService {
|
|
|
// 查询数据
|
|
|
async query(className: string, conditions?: any) {
|
|
|
try {
|
|
|
- const query = new Parse.Query(className);
|
|
|
+ const query = new CloudQuery(className);
|
|
|
if (conditions) {
|
|
|
Object.keys(conditions).forEach(key => {
|
|
|
query.equalTo(key, conditions[key]);
|
|
@@ -67,7 +68,7 @@ export class DatabaseService {
|
|
|
// 更新数据
|
|
|
async update(className: string, objectId: string, data: any) {
|
|
|
try {
|
|
|
- const query = new Parse.Query(className);
|
|
|
+ const query = new CloudQuery(className);
|
|
|
const object = await query.get(objectId);
|
|
|
Object.keys(data).forEach(key => {
|
|
|
object.set(key, data[key]);
|
|
@@ -82,7 +83,7 @@ export class DatabaseService {
|
|
|
// 删除数据
|
|
|
async delete(className: string, objectId: string) {
|
|
|
try {
|
|
|
- const query = new Parse.Query(className);
|
|
|
+ const query = new CloudQuery(className);
|
|
|
const object = await query.get(objectId);
|
|
|
return await object.destroy();
|
|
|
} catch (error) {
|
|
@@ -109,11 +110,11 @@ export class DatabaseService {
|
|
|
// 获取用户的自定义教师列表
|
|
|
async getUserCustomTeachers(userId: string): Promise<CustomTeacher[]> {
|
|
|
try {
|
|
|
- const query = new Parse.Query('CustomTeacher');
|
|
|
+ const query = new CloudQuery('CustomTeacher');
|
|
|
query.equalTo('userId', userId);
|
|
|
- query.ascending('createdAt');
|
|
|
- const results = await query.find();
|
|
|
- return results.map(obj => ({
|
|
|
+ // query.ascending('createdAt');
|
|
|
+ const results:any = await query.find();
|
|
|
+ return results.map((obj:any) => ({
|
|
|
objectId: obj.id,
|
|
|
userId: obj.get('userId'),
|
|
|
name: obj.get('name'),
|
|
@@ -161,7 +162,7 @@ export class DatabaseService {
|
|
|
// 更新自定义教师
|
|
|
async updateCustomTeacher(objectId: string, teacherData: Partial<CustomTeacher>): Promise<CustomTeacher> {
|
|
|
try {
|
|
|
- const query = new Parse.Query('CustomTeacher');
|
|
|
+ const query = new CloudQuery('CustomTeacher');
|
|
|
const teacher = await query.get(objectId);
|
|
|
|
|
|
// 使用类型断言确保字段名是字符串
|
|
@@ -191,7 +192,7 @@ export class DatabaseService {
|
|
|
// 删除自定义教师
|
|
|
async deleteCustomTeacher(objectId: string): Promise<void> {
|
|
|
try {
|
|
|
- const query = new Parse.Query('CustomTeacher');
|
|
|
+ const query = new CloudQuery('CustomTeacher');
|
|
|
const teacher = await query.get(objectId);
|
|
|
await teacher.destroy();
|
|
|
} catch (error) {
|
|
@@ -223,9 +224,9 @@ export class DatabaseService {
|
|
|
|
|
|
async getChatSessions(userId: string) {
|
|
|
try {
|
|
|
- const query = new Parse.Query('ChatSession');
|
|
|
+ const query = new CloudQuery('ChatSession');
|
|
|
query.equalTo('userId', userId);
|
|
|
- query.descending('updatedAt'); // 按更新时间降序排序
|
|
|
+ // query.descending('updatedAt'); // 按更新时间降序排序
|
|
|
return await query.find();
|
|
|
} catch (error) {
|
|
|
console.error('Error getting chat sessions:', error);
|
|
@@ -235,7 +236,7 @@ export class DatabaseService {
|
|
|
|
|
|
async getChatSession(sessionId: string) {
|
|
|
try {
|
|
|
- const query = new Parse.Query('ChatSession');
|
|
|
+ const query = new CloudQuery('ChatSession');
|
|
|
return await query.get(sessionId);
|
|
|
} catch (error) {
|
|
|
console.error('Error getting chat session:', error);
|
|
@@ -245,7 +246,7 @@ export class DatabaseService {
|
|
|
|
|
|
async updateChatSession(sessionId: string, updateData: Partial<ChatSessionData>) {
|
|
|
try {
|
|
|
- const query = new Parse.Query('ChatSession');
|
|
|
+ const query = new CloudQuery('ChatSession');
|
|
|
const session = await query.get(sessionId);
|
|
|
|
|
|
// 使用类型断言确保字段名是字符串
|
|
@@ -265,7 +266,7 @@ export class DatabaseService {
|
|
|
|
|
|
async deleteChatSession(sessionId: string) {
|
|
|
try {
|
|
|
- const query = new Parse.Query('ChatSession');
|
|
|
+ const query = new CloudQuery('ChatSession');
|
|
|
const session = await query.get(sessionId);
|
|
|
return await session.destroy();
|
|
|
} catch (error) {
|