Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Fi1osof committed Nov 13, 2018
1 parent 19a3f58 commit 3f53231
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 7 deletions.
18 changes: 18 additions & 0 deletions __tests__/module/schema/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const requiredTypes = [
"image",
"oldID",
"Imports",
"Votes",
"NotificationTypes",
"Tags",
"ResourceTags",
],
prisma: [
],
Expand Down Expand Up @@ -86,6 +90,20 @@ const requiredTypes = [
],
},
},
{
name: "NotificationType",
fields: {
both: [
"id",
"oldID",
"CreatedBy",
],
prisma: [
],
api: [
],
},
},
]


Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.2.4
===============================
- Added importNotificationTypes

1.2.3
===============================
- Fix dependencies
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@modxclub/import-old-site",
"description": "Importer for modxclub.ru",
"version": "1.2.3",
"version": "1.2.4",
"main": "src/",
"files": [
"src"
Expand Down
159 changes: 153 additions & 6 deletions src/modules/processor/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export default class ImportProcessor extends PrismaProcessor {
await this.importTopics();
await this.importComments();
await this.importTags();
await this.importNotificationTypes();

// await this.importVotes();

Expand Down Expand Up @@ -1088,16 +1089,16 @@ export default class ImportProcessor extends PrismaProcessor {
return root;
}

prepareUri(uri){
prepareUri(uri) {

if(!uri){
if (!uri) {
throw new Error("uri is empty");
}
if(!uri.startsWith("/")){

if (!uri.startsWith("/")) {
uri = `/${uri}`;
}

return uri;
}

Expand Down Expand Up @@ -1198,7 +1199,7 @@ export default class ImportProcessor extends PrismaProcessor {


async writeTag(object) {

// console.log(chalk.green("Create tag object"), object);
// throw new Error("writeTopic error test");

Expand Down Expand Up @@ -1260,6 +1261,152 @@ export default class ImportProcessor extends PrismaProcessor {
*/


/**
* Import NotificationTypes
*/
async importNotificationTypes() {

this.log("Импортируем типы уведомлений", "Info");

// throw new Error("Test");

const {
source,
target,
ctx,
} = this;


const knex = source.getKnex();


const query = source.getQuery("society_notice_types", "source")
;

query
.leftJoin(target.getTableName("NotificationType", "target"), "target.oldID", "source.id")
// .innerJoin(target.getTableName("User"), "User.oldID", "source.createdby")
.whereNull("target.id")
// .whereIn("template", [
// 15,
// ])
;

query
.select([
"source.*",
]);


// query.limit(1);


// console.log(chalk.green("query SQL"), query.toString());

// throw new Error ("Topic error test");

const objects = await query.then();

// console.log("objects", objects);

await this.log(`Было получено ${objects && objects.length} типов уведомлений`, "Info");

// return;

const processor = this.getProcessor(objects, this.writeNotificationType.bind(this));

for await (const result of processor) {

// console.log("writeUser result", result);

}

}


async writeNotificationType(object) {

// console.log(chalk.green("writeNotificationType object"), object);
// throw new Error("writeTopic error test");

const {
ctx,
source,
target,
} = this

const {
db,
} = ctx;

let result;

const {
id: oldID,
type: name,
comment,
} = object;


// Получаем пользователей с этим уведомлением


const query = source.getQuery("society_notice_users", "source")
;

query
.innerJoin(target.getTableName("User"), "User.oldID", "source.user_id")
.where("notice_id", oldID)
;

query.select([
"User.id as userId",
]);

// query.limit(3);

// console.log(chalk.green("query SQL"), query.toString());


const users = await query.then();

// console.log("objects", objects);

await this.log(`Было получено ${users && users.length} пользователей-уведомлений`, "Info");


/**
* Сохраняем объект
*/
result = await db.mutation.createNotificationType({
data: {
oldID,
name,
comment,
CreatedBy: {
connect: {
username: "Fi1osof",
},
},
Users: users && users.length ? {
connect: users.map(({ userId }) => {
return {
id: userId,
}
}),
} : undefined,
},
});


return result;
}

/**
* Eof Import NotificationTypes
*/




}
Expand Down
5 changes: 5 additions & 0 deletions src/modules/schema/database/notificationType.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

type NotificationType{
id: ID! @unique
oldID: Int @unique
}

0 comments on commit 3f53231

Please sign in to comment.