Skip to content

Commit

Permalink
feat: add repository functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyabrain committed Nov 8, 2021
1 parent 057a57e commit 2fb79bd
Show file tree
Hide file tree
Showing 4,703 changed files with 458,566 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"program": "${workspaceFolder}/annotators/annotation-ui/index.js",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "pwa-node"
}
]
}
164 changes: 164 additions & 0 deletions annotators/backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
const {
User,
Post,
Annotation,
UserPostAllocation,
} = require("./sequelize/models");
const { Op } = require("sequelize");

const users = [
{ role: "admin", username: "user_a", password: "asdfasdf", lang: "en" },
];

function createUsers() {
return User.bulkCreate([
{ role: "admin", username: "admin_a", password: "pw_adm_a", lang: "en" },
{ role: "editor", username: "editor_a", password: "pw_ed_a", lang: "en" },
{
role: "annotator",
username: "annotator_a",
password: "pw_ann_a",
lang: "hi",
},
{
role: "annotator",
username: "annotator_b",
password: "pw_ann_b",
lang: "hi",
},
{
role: "annotator",
username: "annotator_c",
password: "pw_ann_c",
lang: "hi",
},
]);
}

function createPosts() {
return Post.bulkCreate([
{ role: "text", text: "asdfasdfasdfasdfasdf" },
{ role: "text", text: "shsdfgsdfgsdfgsafg g" },
{ role: "text", text: "34534fggsdgsadfhgasfg" },
{ role: "text", text: "kgjkfgjhfghkbnkfui" },
{ role: "text", text: "8ououfghdfesxhaweawe" },
{ role: "text", text: "pyowenasmciowp[[[wwe" },
{
role: "image",
url: "https://images.pexels.com/photos/736230/pexels-photo-736230.jpeg",
},
{
role: "image",
url: "https://images.pexels.com/photos/736230/pexels-photo-736230.jpeg",
},
{
role: "image",
url: "https://images.pexels.com/photos/736230/pexels-photo-736230.jpeg",
},
{
role: "image",
url: "https://images.pexels.com/photos/736230/pexels-photo-736230.jpeg",
},
{
role: "image",
url: "https://images.pexels.com/photos/736230/pexels-photo-736230.jpeg",
},
]);
}

function allocatePosts() {
return UserPostAllocation.bulkCreate([
{
userId: "c76bafbb-eda0-4ce7-b88c-9b40e498e056",
postId: "0aa21bb9-ba27-471d-aeff-60feb01a04a9",
status: "pending",
},
{
userId: "c76bafbb-eda0-4ce7-b88c-9b40e498e056",
postId: "1b755657-7b51-499a-a4e8-b5068eb0b911",
status: "pending",
},
{
userId: "c76bafbb-eda0-4ce7-b88c-9b40e498e056",
postId: "4bd5a046-8f20-403d-9e2f-22e9d90f56ee",
status: "pending",
},
{
userId: "c76bafbb-eda0-4ce7-b88c-9b40e498e056",
postId: "7d8bed68-ee16-46e7-85df-33b72f880231",
status: "pending",
},
{
userId: "c76bafbb-eda0-4ce7-b88c-9b40e498e056",
postId: "a3388e67-e379-40d6-9ef5-93a5dfef27e1",
status: "pending",
},
]);
}

function getAllocationForUser({ id }) {
return UserPostAllocation.findAll({
where: {
userId: id,
},
include: [/*User,*/ Post],
});
}

function getAnnotationsForPost({ id }) {
return Annotation.findAll({
where: {
postId: id,
},
});
}

function complexQuery() {
return Annotation.findAll({
where: {
[Op.and]: [{ key: "ogbv" }, { value: 1 }],
},
include: [Post, User],
});
}

async function isUserRegistered({ username, password }) {
const { count, rows } = await User.findAndCountAll({
where: {
[Op.and]: [{ username, password }],
},
});
return count == 0 ? false : rows[0].get({ plain: true });
}

(async function test() {
// await createUsers();
// await createPosts();
// await allocatePosts();
// const allocations = await getAllocationForUser({
// id: "c76bafbb-eda0-4ce7-b88c-9b40e498e056",
// });
// for (const allocation of allocations) {
// console.log(allocation.get({ plain: true }));
// }
// GET ANNOTATIONS
// const annotations = await getAnnotationsForPost({
// id: "0aa21bb9-ba27-471d-aeff-60feb01a04a9",
// });
// for (const annotation of annotations) {
// console.log(annotation.get({ plain: true }));
// }
// TEST complex Query
// const results = await complexQuery({
// id: "0aa21bb9-ba27-471d-aeff-60feb01a04a9",
// });
// for (const result of results) {
// console.log(result.get({ plain: true }));
// }

const status = await isUserRegistered({
username: "annotator_a",
password: "pw_ann_a",
});
console.log(status);
})();
1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/css-beautify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/editorconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/html-beautify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/js-beautify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/nopt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/sequelize

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/sequelize-cli

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotators/backend/node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2fb79bd

Please sign in to comment.