mirror of
https://github.com/bitbaum/datacat.git
synced 2026-12-04 05:30:26 +01:00
* chore: add a formatter, matching the style this repo already writes singleQuote=true was chosen by counting this repo's own imports, not by fleet decree. The fleet is genuinely split and the two repos that already had a .prettierrc disagreed with each other, so there was no standard to restore. Quote style does not cross repo boundaries; having a gate does. Markdown is ignored for now — prettier rewraps prose, which would bury the real diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * style: format with prettier (199 files) Mechanical. No behaviour change. This SHA is listed in .git-blame-ignore-revs so `git blame` skips it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore: teach git blame to skip the reformat Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(ci): put prettier where CI actually installs The formatter was added to the root package.json, but CI installs with working-directory: frontend and then runs npm run verify at the root, so root devDependencies are never installed at all. format:check died with 'prettier: not found' before checking a single file. Root now delegates into frontend the way every other root script already does, and prettier is a devDependency of frontend, whose lockfile CI installs. frontend also needs its own .prettierignore: prettier resolves that file relative to the working directory, so the root one stopped applying the moment the command ran from frontend/ — which is how README.md and Playwright output ended up being checked. * fix(ci): do not format contentlayer's generated output format:check ran green locally and failed in CI on files that do not exist locally: CI builds contentlayer before verify, so .contentlayer/generated is present by the time prettier looks. One generated module imports with assert { type: 'json' }, which prettier's parser rejects outright. A local --check cannot see build output, so generated directories have to be ignored by name rather than discovered. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
211 lines
4.3 KiB
JavaScript
211 lines
4.3 KiB
JavaScript
const prisma = require('../lib/prisma');
|
|
|
|
exports.createSubmission = async (req, res) => {
|
|
const { formId, data, metadata } = req.body;
|
|
const submitterId = req.user?.id || null; // Can be anonymous
|
|
|
|
try {
|
|
// Validate input
|
|
if (!formId || !data) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
message: 'Form ID and data are required',
|
|
});
|
|
}
|
|
|
|
// Check if form exists and is published
|
|
const form = await prisma.form.findFirst({
|
|
where: {
|
|
id: formId,
|
|
isPublished: true,
|
|
},
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
userId: true,
|
|
settings: true,
|
|
},
|
|
});
|
|
|
|
if (!form) {
|
|
return res.status(404).json({
|
|
success: false,
|
|
message: 'Form not found or not published',
|
|
});
|
|
}
|
|
|
|
// Create submission
|
|
const submission = await prisma.submission.create({
|
|
data: {
|
|
formId,
|
|
submitterId,
|
|
data,
|
|
metadata: metadata || {},
|
|
status: 'PENDING',
|
|
source: 'DIRECT',
|
|
ipAddress: req.ip,
|
|
userAgent: req.get('User-Agent'),
|
|
},
|
|
select: {
|
|
id: true,
|
|
formId: true,
|
|
data: true,
|
|
status: true,
|
|
submittedAt: true,
|
|
},
|
|
});
|
|
|
|
res.status(201).json({
|
|
success: true,
|
|
message: 'Form submitted successfully',
|
|
submission,
|
|
});
|
|
} catch (err) {
|
|
console.error('Submit form error:', err);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: 'Server error submitting form',
|
|
});
|
|
}
|
|
};
|
|
|
|
exports.getSubmissions = async (req, res) => {
|
|
const { formId } = req.params;
|
|
const userId = req.user.id;
|
|
const { page = 1, limit = 20, status, search } = req.query;
|
|
|
|
try {
|
|
// Check if user owns the form
|
|
const form = await prisma.form.findFirst({
|
|
where: {
|
|
id: formId,
|
|
userId,
|
|
},
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
},
|
|
});
|
|
|
|
if (!form) {
|
|
return res.status(404).json({
|
|
success: false,
|
|
message: 'Form not found or you do not have access',
|
|
});
|
|
}
|
|
|
|
const skip = (parseInt(page) - 1) * parseInt(limit);
|
|
|
|
const where = {
|
|
formId,
|
|
};
|
|
|
|
if (status) {
|
|
where.status = status.toUpperCase();
|
|
}
|
|
|
|
const [submissions, total] = await Promise.all([
|
|
prisma.submission.findMany({
|
|
where,
|
|
select: {
|
|
id: true,
|
|
data: true,
|
|
metadata: true,
|
|
status: true,
|
|
source: true,
|
|
submittedAt: true,
|
|
submitter: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
email: true,
|
|
},
|
|
},
|
|
},
|
|
orderBy: {
|
|
submittedAt: 'desc',
|
|
},
|
|
skip,
|
|
take: parseInt(limit),
|
|
}),
|
|
prisma.submission.count({ where }),
|
|
]);
|
|
|
|
res.json({
|
|
success: true,
|
|
form,
|
|
submissions,
|
|
pagination: {
|
|
page: parseInt(page),
|
|
limit: parseInt(limit),
|
|
total,
|
|
pages: Math.ceil(total / parseInt(limit)),
|
|
},
|
|
});
|
|
} catch (err) {
|
|
console.error('Get submissions error:', err);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: 'Server error getting submissions',
|
|
});
|
|
}
|
|
};
|
|
|
|
exports.getSubmission = async (req, res) => {
|
|
const { id } = req.params;
|
|
const userId = req.user.id;
|
|
|
|
try {
|
|
const submission = await prisma.submission.findFirst({
|
|
where: {
|
|
id,
|
|
form: {
|
|
userId,
|
|
},
|
|
},
|
|
select: {
|
|
id: true,
|
|
data: true,
|
|
metadata: true,
|
|
status: true,
|
|
source: true,
|
|
ipAddress: true,
|
|
userAgent: true,
|
|
submittedAt: true,
|
|
submitter: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
email: true,
|
|
},
|
|
},
|
|
form: {
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
schema: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!submission) {
|
|
return res.status(404).json({
|
|
success: false,
|
|
message: 'Submission not found or you do not have access',
|
|
});
|
|
}
|
|
|
|
res.json({
|
|
success: true,
|
|
submission,
|
|
});
|
|
} catch (err) {
|
|
console.error('Get submission error:', err);
|
|
res.status(500).json({
|
|
success: false,
|
|
message: 'Server error getting submission',
|
|
});
|
|
}
|
|
};
|