feat: 添加房源审核功能及定时审核任务
This commit is contained in:
@@ -11,7 +11,7 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
connection = await pool.getConnection();
|
||||
|
||||
let sql = 'SELECT * FROM houses WHERE 1=1';
|
||||
let sql = "SELECT * FROM houses WHERE status = 'approved'";
|
||||
const params: any[] = [];
|
||||
|
||||
if (district && district !== '全部') {
|
||||
@@ -42,6 +42,7 @@ export async function GET(request: NextRequest) {
|
||||
createdAt: row.created_at
|
||||
}));
|
||||
|
||||
connection.release();
|
||||
return NextResponse.json({ houses });
|
||||
} catch (error) {
|
||||
console.error('Get houses error:', error);
|
||||
@@ -65,6 +66,7 @@ export async function POST(request: NextRequest) {
|
||||
const [users] = await connection.query<any[]>('SELECT username FROM users WHERE token = ?', [token]);
|
||||
|
||||
if (users.length === 0) {
|
||||
connection.release();
|
||||
return NextResponse.json({ error: '用户不存在' }, { status: 401 });
|
||||
}
|
||||
|
||||
@@ -72,13 +74,14 @@ export async function POST(request: NextRequest) {
|
||||
const { title, description, price, district, address, phone, images } = body;
|
||||
|
||||
if (!title || !price || !district || !address || !phone) {
|
||||
connection.release();
|
||||
return NextResponse.json({ error: '请填写完整信息' }, { status: 400 });
|
||||
}
|
||||
|
||||
const id = crypto.randomUUID();
|
||||
await connection.query(
|
||||
'INSERT INTO houses (id, owner, title, description, price, district, address, phone, images, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[id, users[0].username, title, description || '', Number(price), district, address, phone, JSON.stringify(images || []), new Date()]
|
||||
'INSERT INTO houses (id, owner, title, description, price, district, address, phone, images, status, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[id, users[0].username, title, description || '', Number(price), district, address, phone, JSON.stringify(images || []), 'pending', new Date()]
|
||||
);
|
||||
|
||||
const house = {
|
||||
@@ -91,9 +94,11 @@ export async function POST(request: NextRequest) {
|
||||
address,
|
||||
phone,
|
||||
images: images || [],
|
||||
status: 'pending',
|
||||
createdAt: new Date()
|
||||
};
|
||||
|
||||
connection.release();
|
||||
return NextResponse.json({ success: true, house });
|
||||
} catch (error) {
|
||||
console.error('Create house error:', error);
|
||||
|
||||
Reference in New Issue
Block a user