Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rows.push(row);
}
// Save CSV file and return its URL to the client.
const csv = await parseAsync(rows, { fields: Object.values(fields) });
const buffer = Buffer.from(csv);
const result = await uploadFile({
context,
buffer,
file: {
size: buffer.length,
name: "form_submissions_export.csv",
type: "text/csv"
}
});
return new Response(result);
};
export default async (root: any, args: Object, context: Object) => {
if (!args.parent && !args.url) {
return new NotFoundResponse("Page parent or URL missing.");
}
// We utilize the same query used for listing published pages (single source of truth = less maintenance).
const [page] = await listPublishedPages({ context, args: { ...args, perPage: 1 } });
if (!page) {
return new NotFoundResponse("The requested page was not found.");
}
return new Response(page);
};
export const isInstalled = async (root: any, args: Object, context: Object) => {
const { PbSettings } = context.models;
const settings = await PbSettings.load();
if (!settings) {
return new Response(false);
}
return new Response(settings.data.installation.completed);
};
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(user);
};
const { forms, totalCount } = await plugin.resolve({ root, args: listArgs, context });
if (!Array.isArray(forms) || !Number.isInteger(totalCount)) {
throw Error(
`Resolver plugin "forms-resolver-list-published-forms" must return { forms: [Form], totalCount: Int }!`
);
}
const [form] = forms;
if (!form) {
return new NotFoundResponse("The requested form was not found.");
}
return new Response(form);
};
const { File } = context.models;
const data = [];
for (let i = 0; i < files.length; i++) {
let item = files[i];
let file = await File.findById(item.id);
if (!file) {
file = new File();
}
await file.populate(item).save();
data.push(file);
}
return new Response(data);
};
e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS
) {
const fieldError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: fieldError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: fieldError.message,
data: fieldError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data || null
});
}
return new Response(model);
};
export const isInstalled = async (root: any, args: Object, context: Object) => {
const { PbSettings } = context.models;
const settings = await PbSettings.load();
if (!settings) {
return new Response(false);
}
return new Response(settings.data.installation.completed);
};
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(result);
};
if (!user) {
return new NotFoundResponse(id ? `User "${id}" not found!` : "User not found!");
}
try {
await user.delete();
const authPlugin = context.plugins
.byType("security-authentication-provider")
.filter(pl => pl.hasOwnProperty("deleteUser"))
.pop();
await authPlugin.deleteUser({ user }, context);
return new Response(true);
} catch (e) {
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
};