initial upload
This commit is contained in:
parent
987c99d00b
commit
bb6c0147db
44 changed files with 1884 additions and 131 deletions
92
functions/structure.mjs
Normal file
92
functions/structure.mjs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
|
||||
import {
|
||||
Op
|
||||
} from "sequelize";
|
||||
|
||||
import {
|
||||
ElementTable,
|
||||
AttributeTable
|
||||
} from "../database/models/structure.mjs";
|
||||
|
||||
|
||||
export async function CreateDirectory(parentId, name)
|
||||
{
|
||||
let ParentDirectory = await ElementTable.findByPk(parentId);
|
||||
|
||||
if (ParentDirectory == null) {
|
||||
var NewDirectory = await ElementTable.create({
|
||||
type: 'directory'
|
||||
});
|
||||
} else {
|
||||
var NewDirectory = await ParentDirectory.createChild({
|
||||
type: 'directory'
|
||||
});
|
||||
}
|
||||
|
||||
await NewDirectory.createAttribute({
|
||||
version: NewDirectory.latestVersion,
|
||||
contentType: 'name',
|
||||
contentValue: name
|
||||
})
|
||||
|
||||
return NewDirectory;
|
||||
}
|
||||
|
||||
export async function GetDirectory(directoryId, version = null)
|
||||
{
|
||||
let Directory = await ElementTable.findByPk(directoryId);
|
||||
|
||||
if (Directory == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (version == null) {
|
||||
version = Directory.latestVersion
|
||||
}
|
||||
|
||||
let Attributes = await Directory.getAttribute()
|
||||
|
||||
var Result = {
|
||||
id: Directory.id,
|
||||
version
|
||||
}
|
||||
|
||||
Attributes.forEach((Attribute) => {
|
||||
Result[Attribute.contentType] = Attribute.contentValue
|
||||
});
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
export async function GetDirectories(parentId = null)
|
||||
{
|
||||
let Directories = await ElementTable.findAll({
|
||||
where: {
|
||||
[Op.and]: {
|
||||
type: 'directory',
|
||||
parentId: parentId
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Directories = Directories.map(async (Directory) => {
|
||||
let Attributes = await Directory.getAttribute()
|
||||
|
||||
var Result = {
|
||||
id: Directory.id,
|
||||
version: Directory.latestVersion
|
||||
}
|
||||
|
||||
console.log(Attributes);
|
||||
|
||||
Attributes.forEach((Attribute) => {
|
||||
Result[Attribute.contentType] = Attribute.contentValue
|
||||
});
|
||||
|
||||
return Result;
|
||||
})
|
||||
|
||||
await Promise.all(Directories);
|
||||
|
||||
return Directories;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue