58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import { getPayload } from "payload";
|
|
import config from "@payload-config";
|
|
|
|
export const seedProfiles = async () => {
|
|
const payload = await getPayload({ config });
|
|
|
|
payload.logger.info("Seeding profile data...");
|
|
|
|
payload.logger.warn("Deleting all existing profiles...");
|
|
await payload.delete({
|
|
collection: "profiles",
|
|
where: {
|
|
id: { exists: true },
|
|
},
|
|
});
|
|
|
|
payload.logger.info(`Creating initial sysadmin/developer profile...`);
|
|
try {
|
|
await payload.create({
|
|
collection: "profiles",
|
|
draft: false,
|
|
data: {
|
|
user: (
|
|
await payload.find({
|
|
collection: "users",
|
|
where: {
|
|
role: {
|
|
contains: "developer",
|
|
},
|
|
},
|
|
limit: 1,
|
|
})
|
|
).docs[0].id,
|
|
rank: (
|
|
await payload.find({
|
|
collection: "ranks",
|
|
where: {
|
|
name: {
|
|
equals: "First Lieutenant",
|
|
},
|
|
},
|
|
limit: 1,
|
|
})
|
|
).docs[0].id,
|
|
dossier: {
|
|
enlistmentDate: new Date().toISOString(),
|
|
},
|
|
},
|
|
});
|
|
|
|
payload.logger.info(`Sysadmin/developer profile created.`);
|
|
} catch (_) {
|
|
payload.logger.error("Unable to create sysadmin/developer profile, aborting.");
|
|
return;
|
|
}
|
|
};
|
|
|
|
await seedProfiles();
|